--- /dev/null
+# REQUIRES: x86\r
+\r
+## Confirm both mangled and unmangled names may appear in\r
+## the --dynamic-list file.\r
+\r
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o\r
+\r
+# RUN: echo '{ _Z1fv; extern "C++" { "g()"; }; };' > %t.list\r
+# RUN: ld.lld -pie --dynamic-list %t.list %t.o -o %t\r
+# RUN: llvm-readelf --dyn-syms %t | FileCheck %s\r
+\r
+# CHECK: Symbol table '.dynsym' contains 3 entries:\r
+# CHECK: _Z1fv\r
+# CHECK-NEXT: _Z1gv\r
+\r
+.globl _Z1fv, _Z1gv\r
+_Z1fv:\r
+_Z1gv:\r
--- /dev/null
+# REQUIRES: x86
+
+## Confirm --dynamic-list identifies symbols by entries, including wildcards.
+## Entries need not match a symbol.
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+
+# RUN: echo '{ [fb]o?1*; };' > %t.list
+# RUN: ld.lld -pie --dynamic-list %t.list %t.o -o %t
+# RUN: llvm-readelf --dyn-syms %t | FileCheck %s
+
+# CHECK: Symbol table '.dynsym' contains 4 entries:
+# CHECK: boo1
+# CHECK-NEXT: foo1
+# CHECK-NEXT: foo11
+
+.globl _start, foo1, foo11, foo2, boo1
+foo1:
+foo11:
+foo2:
+boo1:
+_start:
+++ /dev/null
-# 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:
--- /dev/null
+# REQUIRES: x86
+## Verify that the arguments --export-dynamic and --dynamic-list
+## put the correct symbols in the dynamic symbol table.
+
+# RUN: echo "{ *; };" > %t.list
+
+# RUN: echo ".globl shared" > %t.s ; echo "shared = 0xDEADBEEF" >> %t.s
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %t.s -o %t-shared.o
+# RUN: ld.lld --shared %t-shared.o -o %t.so
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+## Use --fatal-warnings to confirm no diagnostics are emitted.
+# RUN: ld.lld --fatal-warnings --defsym=defsym=_start %t.so %t.o -o %t.out
+# RUN: ld.lld --fatal-warnings --defsym=defsym=_start %t.so %t.o -o %texport.out --export-dynamic
+# RUN: ld.lld --fatal-warnings --defsym=defsym=_start %t.so %t.o -o %tlist.out --dynamic-list %t.list
+
+# RUN: llvm-readelf --dyn-syms %t.out | FileCheck %s --check-prefix=NO-EXPORT
+# RUN: llvm-readelf --dyn-syms %texport.out | FileCheck %s --check-prefix=EXPORT
+# RUN: llvm-readelf --dyn-syms %tlist.out | FileCheck %s --check-prefix=EXPORT
+
+# NO-EXPORT: Symbol table '.dynsym' contains 3 entries:
+# NO-EXPORT: GLOBAL DEFAULT {{.*}} shared
+# NO-EXPORT-NEXT: WEAK DEFAULT {{.*}} undef_weak
+
+# EXPORT: Symbol table '.dynsym' contains 8 entries:
+# EXPORT: GLOBAL DEFAULT {{.*}} shared
+# EXPORT-NEXT: WEAK DEFAULT {{.*}} undef_weak
+# EXPORT-NEXT: GLOBAL PROTECTED {{.*}} _start
+# EXPORT-NEXT: GLOBAL DEFAULT ABS abs
+# EXPORT-NEXT: GLOBAL DEFAULT {{.*}} common
+# EXPORT-NEXT: WEAK DEFAULT {{.*}} weak_default
+# EXPORT-NEXT: GLOBAL DEFAULT {{.*}} defsym
+
+.weak undef_weak
+
+.weak weak_default
+weak_default:
+
+.weak weak_internal
+.internal weak_internal
+weak_internal:
+
+.weak weak_hidden
+.internal weak_hidden
+weak_hidden:
+
+.weak weak_protected
+.internal weak_protected
+weak_protected:
+
+.globl shared
+
+.local local
+local:
+
+.comm common, 10
+
+.globl abs
+abs = 0xDEADBEEF
+
+.globl hidden
+.hidden hidden
+hidden:
+
+.globl _start
+.protected _start
+_start:
-## 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 > %tempty.list
# RUN: not ld.lld --dynamic-list %tempty.list 2>&1 | FileCheck --check-prefix=EMPTY %s
# EMPTY: error: {{.*}}.list:1: unexpected EOF
-# RUN: echo foobar > %t1
+# 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: echo '{ "foobar; };' > %t5
+# RUN: not ld.lld --dynamic-list %t5 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: echo '{ extern "BOGUS" { test }; };' > %t6
+# RUN: not ld.lld --dynamic-list %t6 2>&1 | FileCheck -check-prefix=ERR6 %s
# ERR6: {{.*}}:1: Unknown language