Skip to content

Commit dadc852

Browse files
committed
[lld] Add ability to have OUTPUT_FORMAT(binary) in linker script for ld.lld
1 parent d1dc416 commit dadc852

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

lld/ELF/ScriptParser.cpp

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,12 @@ void ScriptParser::readOutputFormat() {
475475
consume(")");
476476
}
477477
s = config->bfdname;
478+
479+
if (s == "binary") {
480+
config->oFormatBinary = true;
481+
return;
482+
}
483+
478484
if (s.consume_back("-freebsd"))
479485
config->osabi = ELFOSABI_FREEBSD;
480486

@@ -837,8 +843,7 @@ Expr ScriptParser::readAssert() {
837843
};
838844
}
839845

840-
#define ECase(X) \
841-
{ #X, X }
846+
#define ECase(X) {#X, X}
842847
constexpr std::pair<const char *, unsigned> typeMap[] = {
843848
ECase(SHT_PROGBITS), ECase(SHT_NOTE), ECase(SHT_NOBITS),
844849
ECase(SHT_INIT_ARRAY), ECase(SHT_FINI_ARRAY), ECase(SHT_PREINIT_ARRAY),
@@ -850,7 +855,8 @@ constexpr std::pair<const char *, unsigned> typeMap[] = {
850855
// "(TYPE=<value>)".
851856
// Tok1 and Tok2 are next 2 tokens peeked. See comment for
852857
// readSectionAddressType below.
853-
bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok1, StringRef tok2) {
858+
bool ScriptParser::readSectionDirective(OutputSection *cmd, StringRef tok1,
859+
StringRef tok2) {
854860
if (tok1 != "(")
855861
return false;
856862
if (tok2 != "NOLOAD" && tok2 != "COPY" && tok2 != "INFO" &&
@@ -1349,10 +1355,10 @@ static std::optional<uint64_t> parseFlag(StringRef tok) {
13491355
// Example: SHF_EXECINSTR & !SHF_WRITE means with flag SHF_EXECINSTR and
13501356
// without flag SHF_WRITE.
13511357
std::pair<uint64_t, uint64_t> ScriptParser::readInputSectionFlags() {
1352-
uint64_t withFlags = 0;
1353-
uint64_t withoutFlags = 0;
1354-
expect("(");
1355-
while (!errorCount()) {
1358+
uint64_t withFlags = 0;
1359+
uint64_t withoutFlags = 0;
1360+
expect("(");
1361+
while (!errorCount()) {
13561362
StringRef tok = unquote(next());
13571363
bool without = tok.consume_front("!");
13581364
if (std::optional<uint64_t> flag = parseFlag(tok)) {
@@ -1490,7 +1496,8 @@ Expr ScriptParser::readPrimary() {
14901496
readExpr();
14911497
expect(")");
14921498
script->seenRelroEnd = true;
1493-
return [=] { return alignToPowerOf2(script->getDot(), config->maxPageSize); };
1499+
return
1500+
[=] { return alignToPowerOf2(script->getDot(), config->maxPageSize); };
14941501
}
14951502
if (tok == "DEFINED") {
14961503
StringRef name = unquote(readParenLiteral());

0 commit comments

Comments
 (0)