Skip to content

Commit

Permalink
[ELF] Improve wildcard tests for input section descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
MaskRay committed Mar 6, 2024
1 parent 6bf6128 commit 5ff3f66
Showing 1 changed file with 42 additions and 12 deletions.
54 changes: 42 additions & 12 deletions lld/test/ELF/linkerscript/wildcards.s
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# REQUIRES: x86
# RUN: split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t/asm -o %t.o
# RUN: rm -rf %t && split-file %s %t && cd %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %t/asm -o a.o

## Default case: abc and abx included in text.
# RUN: echo "SECTIONS { \
# RUN: .text : { *(.abc .abx) } }" > %t.script
# RUN: ld.lld -o %t.out --script %t.script %t.o
# RUN: llvm-objdump --section-headers %t.out | \
# RUN: ld.lld -o out --script %t.script a.o
# RUN: llvm-objdump --section-headers out | \
# RUN: FileCheck -check-prefix=SEC-DEFAULT %s
# SEC-DEFAULT: Sections:
# SEC-DEFAULT-NEXT: Idx Name Size
Expand All @@ -23,15 +23,15 @@
## Now replace the symbol with '?' and check that results are the same.
# RUN: echo "SECTIONS { \
# RUN: .text : { *(.abc .ab?) } }" > %t.script
# RUN: ld.lld -o %t.out --script %t.script %t.o
# RUN: llvm-objdump --section-headers %t.out | \
# RUN: ld.lld -o out --script %t.script a.o
# RUN: llvm-objdump --section-headers out | \
# RUN: FileCheck -check-prefix=SEC-DEFAULT %s

## Now see how replacing '?' with '*' will consume whole abcd.
# RUN: echo "SECTIONS { \
# RUN: .text : { *(.abc .ab*) } }" > %t.script
# RUN: ld.lld -o %t.out --script %t.script %t.o
# RUN: llvm-objdump --section-headers %t.out | \
# RUN: ld.lld -o out --script %t.script a.o
# RUN: llvm-objdump --section-headers out | \
# RUN: FileCheck -check-prefix=SEC-ALL %s
# SEC-ALL: Sections:
# SEC-ALL-NEXT: Idx Name Size
Expand All @@ -47,8 +47,8 @@
## All sections started with .a are merged.
# RUN: echo "SECTIONS { \
# RUN: .text : { *(.a*) } }" > %t.script
# RUN: ld.lld -o %t.out --script %t.script %t.o
# RUN: llvm-objdump --section-headers %t.out | \
# RUN: ld.lld -o out --script %t.script a.o
# RUN: llvm-objdump --section-headers out | \
# RUN: FileCheck -check-prefix=SEC-NO %s
# SEC-NO: Sections:
# SEC-NO-NEXT: Idx Name Size
Expand Down Expand Up @@ -84,10 +84,40 @@
.globl _start
_start:

#--- bracket.lds
# RUN: ld.lld -T bracket.lds a.o -o out
# RUN: llvm-objdump --section-headers out | FileCheck %s --check-prefix=SEC-DEFAULT
SECTIONS {
.text : { *([.]abc .ab[v-y] ) }
}

## Test a few non-wildcard meta characters rejected by GNU ld.

#--- lbrace.lds
# RUN: ld.lld -T lbrace.lds a.o -o out
SECTIONS {
.text : { *(.a* { ) }
}

#--- lparen.lds
## ( is recognized as a section name pattern. Note, ( is rejected by GNU ld.
# RUN: ld.lld -T %t/lparen.lds %t.o -o %t.out
# RUN: llvm-objdump --section-headers %t.out | FileCheck --check-prefix=SEC-NO %s
# RUN: ld.lld -T lparen.lds a.o -o out
# RUN: llvm-objdump --section-headers out | FileCheck --check-prefix=SEC-NO %s
SECTIONS {
.text : { *(.a* ( ) }
}

#--- rbrace.lds
# RUN: ld.lld -T rbrace.lds a.o -o out
SECTIONS {
.text : { *(.a* } ) }
}

#--- rparen.lds
# RUN: not ld.lld -T rparen.lds %t.o 2>&1 | FileCheck %s --check-prefix=ERR-RPAREN --match-full-lines --strict-whitespace
# ERR-RPAREN:{{.*}}: expected filename pattern
# ERR-RPAREN-NEXT:>>> .text : { *(.a* ) ) }
# ERR-RPAREN-NEXT:>>> ^
SECTIONS {
.text : { *(.a* ) ) }
}

0 comments on commit 5ff3f66

Please sign in to comment.