-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[lld] Add ability to have OUTPUT_FORMAT(binary) in linker script for ld.lld #97765
[lld] Add ability to have OUTPUT_FORMAT(binary) in linker script for ld.lld #97765
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-lld-elf @llvm/pr-subscribers-lld Author: Can (droptopx) ChangesThis fixes #87891. Full diff: https://github.com/llvm/llvm-project/pull/97765.diff 1 Files Affected:
diff --git a/lld/ELF/ScriptParser.cpp b/lld/ELF/ScriptParser.cpp
index db46263115242..77cbfae30d4d0 100644
--- a/lld/ELF/ScriptParser.cpp
+++ b/lld/ELF/ScriptParser.cpp
@@ -475,6 +475,12 @@ void ScriptParser::readOutputFormat() {
consume(")");
}
s = config->bfdname;
+
+ if (s == "binary") {
+ config->oFormatBinary = true;
+ return;
+ }
+
if (s.consume_back("-freebsd"))
config->osabi = ELFOSABI_FREEBSD;
@@ -837,8 +843,7 @@ Expr ScriptParser::readAssert() {
};
}
-#define ECase(X) \
- { #X, X }
+#define ECase(X) {#X, X}
constexpr std::pair<const char *, unsigned> typeMap[] = {
ECase(SHT_PROGBITS), ECase(SHT_NOTE), ECase(SHT_NOBITS),
ECase(SHT_INIT_ARRAY), ECase(SHT_FINI_ARRAY), ECase(SHT_PREINIT_ARRAY),
@@ -850,7 +855,8 @@ constexpr std::pair<const char *, unsigned> typeMap[] = {
// "(TYPE=<value>)".
// Tok1 and Tok2 are next 2 tokens peeked. See comment for
// readSectionAddressType below.
-bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok1, StringRef tok2) {
+bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok1,
+ StringRef tok2) {
if (tok1 != "(")
return false;
if (tok2 != "NOLOAD" && tok2 != "COPY" && tok2 != "INFO" &&
@@ -1349,10 +1355,10 @@ static std::optional<uint64_t> parseFlag(StringRef tok) {
// Example: SHF_EXECINSTR & !SHF_WRITE means with flag SHF_EXECINSTR and
// without flag SHF_WRITE.
std::pair<uint64_t, uint64_t> ScriptParser::readInputSectionFlags() {
- uint64_t withFlags = 0;
- uint64_t withoutFlags = 0;
- expect("(");
- while (!errorCount()) {
+ uint64_t withFlags = 0;
+ uint64_t withoutFlags = 0;
+ expect("(");
+ while (!errorCount()) {
StringRef tok = unquote(next());
bool without = tok.consume_front("!");
if (std::optional<uint64_t> flag = parseFlag(tok)) {
@@ -1490,7 +1496,8 @@ Expr ScriptParser::readPrimary() {
readExpr();
expect(")");
script->seenRelroEnd = true;
- return [=] { return alignToPowerOf2(script->getDot(), config->maxPageSize); };
+ return
+ [=] { return alignToPowerOf2(script->getDot(), config->maxPageSize); };
}
if (tok == "DEFINED") {
StringRef name = unquote(readParenLiteral());
|
Hang on while I fix the unintended automatic formatting. |
dadc852
to
f8dd76c
Compare
Should be good now! |
This needs a test in |
Okay, I want to write test(s) for this but I'm not sure what we need to be testing for here. Why would we want to test for the behaviors of Is the test for the case where there are more than one |
We want to test the behavior when more than one After closer inspection of GNU ld's behavior, I think we probably should ignore extra OUTPUT_FORMAT commands. #98837 |
Closing as #98837 has been merged. Thanks. |
This fixes #87891.