diff options
author | George Rimar <grimar@accesssoftek.com> | 2019-07-10 14:36:48 +0000 |
---|---|---|
committer | George Rimar <grimar@accesssoftek.com> | 2019-07-10 14:36:48 +0000 |
commit | 8c085cf1939692b2b6b22a9fb3ac9f5cf9ab28ce (patch) | |
tree | c14b05b395ca32a5c5d279cecfdf8b3446bc3e12 | |
parent | b1e76d1d41c2303f70b53e352bdefbff2a2a9d37 (diff) |
[LLD][ELF] - Linkerscript: fix FILL() expressions handling.
D64130 introduced a bug described in the following message:
https://reviews.llvm.org/D64130#1571560
The problem can happen with the following script:
SECTIONS {
.out : {
...
FILL(0x10101010)
*(.aaa)
...
}
The current code tries to read (0x10101010) as an expression and
does not break when meets *, what results in a script parsing error.
In this patch, I verify that FILL command's expression always wrapped in ().
And at the same time =<fillexp> expression can be both wrapped or unwrapped.
I checked it matches to bfd/gold.
Differential revision: https://reviews.llvm.org/D64476
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@365635 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | ELF/ScriptParser.cpp | 2 | ||||
-rw-r--r-- | test/ELF/linkerscript/fill.test | 5 | ||||
-rw-r--r-- | test/ELF/linkerscript/sections-padding.s | 11 |
3 files changed, 15 insertions, 3 deletions
diff --git a/ELF/ScriptParser.cpp b/ELF/ScriptParser.cpp index b0f710b78..9076a1cf8 100644 --- a/ELF/ScriptParser.cpp +++ b/ELF/ScriptParser.cpp @@ -828,7 +828,9 @@ OutputSection *ScriptParser::readOutputSectionDescription(StringRef outSec) { // We handle the FILL command as an alias for =fillexp section attribute, // which is different from what GNU linkers do. // https://sourceware.org/binutils/docs/ld/Output-Section-Data.html + expect("("); cmd->filler = readFill(); + expect(")"); } else if (tok == "SORT") { readSort(); } else if (tok == "INCLUDE") { diff --git a/test/ELF/linkerscript/fill.test b/test/ELF/linkerscript/fill.test index 10417bb4f..9ba3b2a7b 100644 --- a/test/ELF/linkerscript/fill.test +++ b/test/ELF/linkerscript/fill.test @@ -7,6 +7,7 @@ SECTIONS { .out : { FILL(0x11111111) . += 2; + FILL(0x10101010) *(.aaa) . += 4; *(.bbb) @@ -18,3 +19,7 @@ SECTIONS { # CHECK: Contents of section .out: # CHECK-NEXT: 2222aa22 222222bb 22222222 22222222 + +# RUN: echo 'SECTIONS { .out : { FILL 0x11111111 } }' > %t.script +# RUN: not ld.lld -o /dev/null --script %t.script 2>&1 | FileCheck %s --check-prefix=ERR +# ERR: ( expected, but got 0x11111111 diff --git a/test/ELF/linkerscript/sections-padding.s b/test/ELF/linkerscript/sections-padding.s index 7b90746d8..ab5d122cf 100644 --- a/test/ELF/linkerscript/sections-padding.s +++ b/test/ELF/linkerscript/sections-padding.s @@ -7,11 +7,16 @@ # RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=YES %s # YES: 66000011 22000011 22000011 22000011 +# RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x1100+0x22 }" > %t.script +# RUN: ld.lld -o %t.out --script %t.script %t +# RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=YES2 %s +# YES2: 66000011 22000011 22000011 22000011 + ## Confirming that address was correct: # RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =0x99887766 }" > %t.script # RUN: ld.lld -o %t.out --script %t.script %t -# RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=YES2 %s -# YES2: 66998877 66998877 66998877 66998877 +# RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=YES3 %s +# YES3: 66998877 66998877 66998877 66998877 ## Default padding value is 0x00: # RUN: echo "SECTIONS { .mysec : { *(.mysec*) } }" > %t.script @@ -51,7 +56,7 @@ # RUN: ld.lld -o %t.out --script %t.script %t # RUN: llvm-objdump -s %t.out | FileCheck -check-prefix=YES %s -## Check we report an error if expression value is larger that 32-bits. +## Check we report an error if expression value is larger than 32-bits. # RUN: echo "SECTIONS { .mysec : { *(.mysec*) } =(0x11 << 32) }" > %t.script # RUN: not ld.lld -o %t.out --script %t.script %t 2>&1 | FileCheck --check-prefix=ERR3 %s # ERR3: filler expression result does not fit 32-bit: 0x1100000000 |