The current tokenize-whole-file approach has a few limitations. * Lack of state information: `maybeSplitExpr` is needed to parse expressions. It's infeasible to add new states to behave more like GNU ld. * `readInclude` may insert tokens in the middle, leading to a time complexity issue with N-nested `INCLUDE`. * line/column information for diagnostics are inaccurate, especially after an `INCLUDE`. * `getLineNumber` cannot be made more efficient without significant code complexity and memory consumption. https://reviews.llvm.org/D104137 The patch switches to a traditional lexer that generates tokens lazily. * `atEOF` behavior is modified: we need to call `peek` to determine EOF. * `peek` and `next` cannot call `setError` upon `atEOF`. * Since `consume` no longer reports an error upon `atEOF`, the idiom `while (!errorCount() && !consume(")"))` would cause a dead loop. Use `while (peek() != ")" && !atEOF()) { ... } expect(")")` instead. * An include stack is introduced to handle `readInclude`. This can be utilized to address #93947 properly. * `tokens` and `pos` are removed. * `commandString` is reimplemented. Since it is used in -Map output, `\n` needs to be replaced with space. Pull Request: https://github.com/llvm/llvm-project/pull/100493
61 lines
2.7 KiB
Plaintext
61 lines
2.7 KiB
Plaintext
# REQUIRES: x86
|
|
|
|
# RUN: echo '.quad sym3; .quad sym4; .section .foo.1, "a"; .quad 1' > %t.s
|
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t.s -o %t.o
|
|
|
|
# RUN: ld.lld -o %t %t.o -Map=%t.map --script %s
|
|
# RUN: FileCheck -strict-whitespace %s < %t.map
|
|
|
|
SECTIONS {
|
|
. = 0x1000; # tabs
|
|
.foo : {
|
|
BYTE ( 0x11 )
|
|
SHORT (0x1122)
|
|
LONG(0x11223344)
|
|
QUAD(0x1122334455667788)
|
|
PROVIDE_HIDDEN(sym4 = .);
|
|
. += 0x1000;
|
|
*(.foo.1)
|
|
PROVIDE(unused1 = 0xff);
|
|
HIDDEN( sym6 = . );
|
|
. += 0x123 *
|
|
(1 + 1);
|
|
foo = .;
|
|
bar = 0x42 - 0x26;
|
|
}
|
|
sym1 = .;
|
|
. += 0x500;
|
|
sym2 = .;
|
|
PROVIDE(unused2 = 0xff);
|
|
PROVIDE(sym3 = 42);
|
|
}
|
|
|
|
# CHECK: VMA LMA Size Align Out In Symbol
|
|
# CHECK-NEXT: 0 0 1000 1 . = 0x1000
|
|
# CHECK-NEXT: 1000 1000 125d 1 .foo
|
|
# CHECK-NEXT: 1000 1000 1 1 BYTE ( 0x11 )
|
|
# CHECK-NEXT: 1001 1001 2 1 SHORT (0x1122)
|
|
# CHECK-NEXT: 1003 1003 4 1 LONG(0x11223344)
|
|
# CHECK-NEXT: 1007 1007 8 1 QUAD(0x1122334455667788)
|
|
# CHECK-NEXT: 100f 100f 0 1 PROVIDE_HIDDEN(sym4 = .)
|
|
# CHECK-NEXT: 100f 100f 1000 1 . += 0x1000
|
|
# CHECK-NEXT: 200f 200f 8 1 {{.*}}{{/|\\}}map-file.test.tmp.o:(.foo.1)
|
|
# CHECK-NEXT: 2017 2017 0 1 HIDDEN( sym6 = . )
|
|
# CHECK-NEXT: 2017 2017 246 1 . += 0x123 * (1 + 1)
|
|
# CHECK-NEXT: 225d 225d 0 1 foo = .
|
|
# CHECK-NEXT: 225d 225d 0 1 bar = 0x42 - 0x26
|
|
# CHECK-NEXT: 225d 225d 0 1 sym1 = .
|
|
# CHECK-NEXT: 225d 225d 500 1 . += 0x500
|
|
# CHECK-NEXT: 275d 275d 0 1 sym2 = .
|
|
# CHECK-NEXT: 275d 275d 0 1 PROVIDE(sym3 = 42)
|
|
# CHECK-NEXT: 2760 2760 10 4 .text
|
|
# CHECK-NEXT: 2760 2760 10 4 {{.*}}{{/|\\}}map-file.test.tmp.o:(.text)
|
|
# CHECK-NEXT: 0 0 8 1 .comment
|
|
# CHECK-NEXT: 0 0 8 1 <internal>:(.comment)
|
|
# CHECK-NEXT: 0 0 c0 8 .symtab
|
|
# CHECK-NEXT: 0 0 c0 8 <internal>:(.symtab)
|
|
# CHECK-NEXT: 0 0 2f 1 .shstrtab
|
|
# CHECK-NEXT: 0 0 2f 1 <internal>:(.shstrtab)
|
|
# CHECK-NEXT: 0 0 22 1 .strtab
|
|
# CHECK-NEXT: 0 0 22 1 <internal>:(.strtab)
|