diff --git a/lld/test/ELF/Inputs/export-symbol-types.s b/lld/test/ELF/Inputs/export-symbol-types.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/Inputs/export-symbol-types.s @@ -0,0 +1,2 @@ +.globl import +import = 0xDEADBEEF diff --git a/lld/test/ELF/Inputs/invalid-dynamic-list-1.list b/lld/test/ELF/Inputs/invalid-dynamic-list-1.list new file mode 100644 --- /dev/null +++ b/lld/test/ELF/Inputs/invalid-dynamic-list-1.list @@ -0,0 +1 @@ +{ "foobar; }; diff --git a/lld/test/ELF/Inputs/invalid-dynamic-list-2.list b/lld/test/ELF/Inputs/invalid-dynamic-list-2.list new file mode 100644 --- /dev/null +++ b/lld/test/ELF/Inputs/invalid-dynamic-list-2.list @@ -0,0 +1 @@ +{ extern "BOGUS" { test }; }; diff --git a/lld/test/ELF/dynamic-list-patterns.s b/lld/test/ELF/dynamic-list-patterns.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/dynamic-list-patterns.s @@ -0,0 +1,27 @@ +# REQUIRES: x86 + +## Confirm --dynamic-list identifies symbols by patterns, including wildcards. +## Patterns need not match a symbol. Both mangled and unmangled names may +## appears in the --dynamic-list file. + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o + +# RUN: echo "{ [fb]o?1*; _Z1fv; extern \"C++\" { \"g()\"; }; };" > %t.list +# RUN: ld.lld -pie --dynamic-list %t.list %t.o -o %t.elf +# RUN: llvm-readelf --dyn-symbols %t.elf | FileCheck %s + +# CHECK: Symbol table '.dynsym' contains 6 entries: +# CHECK-DAG: _Z1fv +# CHECK-DAG: _Z1gv +# CHECK-DAG: boo1 +# CHECK-DAG: foo1 +# CHECK-DAG: foo11 + +.globl _start, foo1, foo11, foo2, boo1, _Z1fv, _Z1gv +foo1: +foo11: +foo2: +boo1: +_start: +_Z1fv: +_Z1gv: diff --git a/lld/test/ELF/dynamic-list-wildcard.s b/lld/test/ELF/dynamic-list-wildcard.s deleted file mode 100644 --- a/lld/test/ELF/dynamic-list-wildcard.s +++ /dev/null @@ -1,17 +0,0 @@ -# REQUIRES: x86 - -# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t - -# RUN: echo "{ foo1*; };" > %t.list -# RUN: ld.lld -pie --dynamic-list %t.list %t -o %t -# RUN: llvm-nm -D %t | FileCheck %s - -# CHECK: foo1 -# CHECK-NEXT: foo11 -# CHECK-NOT: {{.}} - -.globl _start, foo1, foo11, foo2 -foo1: -foo11: -foo2: -_start: diff --git a/lld/test/ELF/export-dynamic-symbol.s b/lld/test/ELF/export-dynamic-symbol.s --- a/lld/test/ELF/export-dynamic-symbol.s +++ b/lld/test/ELF/export-dynamic-symbol.s @@ -1,15 +1,16 @@ # REQUIRES: x86 # RUN: rm -f %t.a -# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/archive2.s -o %t1.o +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/archive2.s -o %t1.o # RUN: llvm-ar rcs %t.a %t1.o # RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t2.o -# RUN: ld.lld -shared -o %t.so --export-dynamic-symbol foo %t.a %t2.o -# RUN: llvm-readelf -dyn-symbols %t.so | FileCheck %s +# Use --fatal-warnings to confirm no diagnostics are emitted for unexportable symbols. +# RUN: ld.lld -shared --fatal-warnings -o %t.so --export-dynamic-symbol foo --export-dynamic-symbol nomatch %t.a %t2.o +# RUN: llvm-readelf -dyn-symbols %t.so | FileCheck %s --implicit-check-not=nomatch -# RUN: ld.lld -shared -o %t.so --export-dynamic --export-dynamic-symbol foo %t.a %t2.o -# RUN: llvm-readelf -dyn-symbols %t.so | FileCheck %s +# RUN: ld.lld -shared --fatal-warnings -o %t.so --export-dynamic --export-dynamic-symbol foo --export-dynamic-symbol nomatch %t.a %t2.o +# RUN: llvm-readelf -dyn-symbols %t.so | FileCheck %s --implicit-check-not=nomatch # CHECK: foo diff --git a/lld/test/ELF/export-symbol-types.s b/lld/test/ELF/export-symbol-types.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/export-symbol-types.s @@ -0,0 +1,63 @@ +## Not exported: +## - local symbols +## - hidden symbols +## +## Exported: +## - undefined symbols +## - weak undefined symbols +## - imported symbols +## - common symbols +## - weak symbols +## - abs symbols +## - protected symbols +## - symbols generated by the linker + +# RUN: echo "{ undef; weakref; import; local; common; weak; abs; hidden; _start; defsym; };" > %t.list + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/export-symbol-types.s -o %t-shared.o +# RUN: ld.lld --shared %t-shared.o -o %t.so + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t-elf.o +# Use --fatal-warnings to confirm no diagnostics are emitted +# RUN: ld.lld --fatal-warnings --defsym=defsym=_start %t.so %t-elf.o -o %t.elf --export-dynamic + +# RUN: ld.lld --fatal-warnings --defsym=defsym=_start %t.so %t-elf.o -o %tlist.elf --dynamic-list %t.list + +# RUN: llvm-readelf --dyn-symbols %t.elf | FileCheck %s +# RUN: llvm-readelf --dyn-symbols %tlist.elf | FileCheck %s + +# CHECK: Symbol table '.dynsym' contains 8 entries: +# CHECK-DAG: GLOBAL PROTECTED {{.*}} _start +# CHECK-DAG: GLOBAL DEFAULT {{.*}} common +# CHECK-DAG: GLOBAL DEFAULT {{.*}} import +# CHECK-DAG: GLOBAL DEFAULT {{.*}} abs +# CHECK-DAG: GLOBAL DEFAULT {{.*}} defsym +# CHECK-DAG: WEAK DEFAULT {{.*}} weakref +# CHECK-DAG: WEAK DEFAULT {{.*}} weak + +.weak weakref + +.globl import + +.local local +local: + ret + +.comm common, 10 + +.weak weak +weak: + ret + +.globl abs +abs = 0xDEADBEEF + +.globl hidden +.hidden hidden +hidden: + ret + +.globl _start +.protected _start +_start: + ret diff --git a/lld/test/ELF/invalid-dynamic-list.test b/lld/test/ELF/invalid-dynamic-list.test --- a/lld/test/ELF/invalid-dynamic-list.test +++ b/lld/test/ELF/invalid-dynamic-list.test @@ -1,37 +1,24 @@ -## Different "echo" commands on Windows interpret quoted strings and -## wildcards in similar but different way (On Windows, ARGV tokenization -## and wildcard expansion are not done by the shell but by each command.) -## Because of that reason, this test fails on some Windows environment. -## We can't write quoted strings that are interpreted the same way -## by all echo commands. So, we don't want to run this on Windows. - -# REQUIRES: shell - -# RUN: mkdir -p %t.dir - # RUN: echo foobar > %t1 # RUN: not ld.lld --dynamic-list %t1 2>&1 | FileCheck -check-prefix=ERR1 %s # ERR1: {{.*}}:1: { expected, but got foobar -# RUN: echo "{ foobar;" > %t1 -# RUN: not ld.lld --dynamic-list %t1 2>&1 | FileCheck -check-prefix=ERR2 %s +# RUN: echo "{ foobar;" > %t2 +# RUN: not ld.lld --dynamic-list %t2 2>&1 | FileCheck -check-prefix=ERR2 %s # ERR2: {{.*}}:1: unexpected EOF ## Missing ';' before '}' -# RUN: echo "{ foobar }" > %t1 -# RUN: not ld.lld --dynamic-list %t1 2>&1 | FileCheck -check-prefix=ERR3 %s +# RUN: echo "{ foobar }" > %t3 +# RUN: not ld.lld --dynamic-list %t3 2>&1 | FileCheck -check-prefix=ERR3 %s # ERR3: {{.*}}:1: ; expected, but got } ## Missing final ';' -# RUN: echo "{ foobar; }" > %t1 -# RUN: not ld.lld --dynamic-list %t1 2>&1 | FileCheck -check-prefix=ERR4 %s +# RUN: echo "{ foobar; }" > %t4 +# RUN: not ld.lld --dynamic-list %t4 2>&1 | FileCheck -check-prefix=ERR4 %s # ERR4: {{.*}}:1: unexpected EOF -## Missing \" in foobar definition -# RUN echo "{ \"foobar; };" > %t1 -# RUN: not ld.lld --dynamic-list %t1 2>&1 | FileCheck -check-prefix=ERR5 %s -# ERR5: {{.*}}:1: unexpected EOF +## Missing " in foobar definition ++# RUN: not ld.lld --dynamic-list %S/Inputs/invalid-dynamic-list-1.list 2>&1 | FileCheck -check-prefix=ERR5 %s ++# ERR5: {{.*}}:1: unclosed quote -# RUN: echo "{ extern \"BOGUS\" { test }; };" > %t1 -# RUN: not ld.lld --dynamic-list %t1 2>&1 | FileCheck -check-prefix=ERR6 %s +RUN: not ld.lld --dynamic-list %S/Inputs/invalid-dynamic-list-2.list 2>&1 | FileCheck -check-prefix=ERR6 %s # ERR6: {{.*}}:1: Unknown language