ld: Support the -exclude-symbols option via COFF def files, with the EXCLUDE_SYMBOLS...
authorMartin Storsjö <martin@martin.st>
Fri, 22 Jul 2022 21:57:19 +0000 (00:57 +0300)
committerMartin Storsjö <martin@martin.st>
Mon, 1 Aug 2022 20:18:00 +0000 (23:18 +0300)
This was requested in review.

ld/deffile.h
ld/deffilep.y
ld/testsuite/ld-pe/exclude-symbols-def-i386.d [new file with mode: 0644]
ld/testsuite/ld-pe/exclude-symbols-def-i386.s [new file with mode: 0644]
ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d [new file with mode: 0644]
ld/testsuite/ld-pe/exclude-symbols-def-x86_64.s [new file with mode: 0644]
ld/testsuite/ld-pe/exclude-symbols-def.def [new file with mode: 0644]
ld/testsuite/ld-pe/pe.exp

index 306ae3a6f755deab04160a077c147943c0777205..a247639628e3eb502dec85ea11711474694ab579 100644 (file)
@@ -99,6 +99,8 @@ typedef struct def_file {
 
   /* Only expected from .drectve sections, not .DEF files.  */
   def_file_aligncomm *aligncomms;
+
+  /* From EXCLUDE_SYMBOLS or embedded directives. */
   def_file_exclude_symbol *exclude_symbols;
 
 } def_file;
index dc0cb4db944a3d1fb1ec6bfc37da5e6a4efbae6a..27db336e0f5e626499b229c4888369ee5023e823 100644 (file)
@@ -249,6 +249,7 @@ keyword_as_name: BASE { $$ = "BASE"; }
         | DATAL { $$ = "data"; }
         | DESCRIPTION { $$ = "DESCRIPTION"; }
         | DIRECTIVE { $$ = "DIRECTIVE"; }
+        | EXCLUDE_SYMBOLS { $$ = "EXCLUDE_SYMBOLS"; }
         | EXECUTE { $$ = "EXECUTE"; }
         | EXPORTS { $$ = "EXPORTS"; }
         | HEAPSIZE { $$ = "HEAPSIZE"; }
@@ -337,6 +338,7 @@ anylang_id: ID              { $$ = $1; }
 
 symbol_list:
        anylang_id { def_exclude_symbols ($1); }
+       |       symbol_list anylang_id { def_exclude_symbols ($2); }
        |       symbol_list ',' anylang_id { def_exclude_symbols ($3); }
        ;
 
@@ -1352,6 +1354,7 @@ tokens[] =
   { "data", DATAL },
   { "DESCRIPTION", DESCRIPTION },
   { "DIRECTIVE", DIRECTIVE },
+  { "EXCLUDE_SYMBOLS", EXCLUDE_SYMBOLS },
   { "EXECUTE", EXECUTE },
   { "EXPORTS", EXPORTS },
   { "HEAPSIZE", HEAPSIZE },
diff --git a/ld/testsuite/ld-pe/exclude-symbols-def-i386.d b/ld/testsuite/ld-pe/exclude-symbols-def-i386.d
new file mode 100644 (file)
index 0000000..1f15c89
--- /dev/null
@@ -0,0 +1,10 @@
+#source: exclude-symbols-def-i386.s
+#target: i?86-*-cygwin* i?86-*-pe i?86-*-mingw*
+#ld: -shared ${srcdir}/${subdir}/exclude-symbols-def.def
+#objdump: -p
+
+#...
+.*\[[  ]*0\] sym1
+.*\[[  ]*1\] sym3
+.*\[[  ]*2\] sym5
+#pass
diff --git a/ld/testsuite/ld-pe/exclude-symbols-def-i386.s b/ld/testsuite/ld-pe/exclude-symbols-def-i386.s
new file mode 100644 (file)
index 0000000..fd533bb
--- /dev/null
@@ -0,0 +1,11 @@
+.global _sym1
+.global _sym2
+.global _sym3
+.global _sym4
+.global _sym5
+_sym1:
+_sym2:
+_sym3:
+_sym4:
+_sym5:
+  ret
diff --git a/ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d b/ld/testsuite/ld-pe/exclude-symbols-def-x86_64.d
new file mode 100644 (file)
index 0000000..39de881
--- /dev/null
@@ -0,0 +1,10 @@
+#source: exclude-symbols-def-x86_64.s
+#target: x86_64-*-cygwin* x86_64-*-pe x86_64-*-mingw*
+#ld: -shared ${srcdir}/${subdir}/exclude-symbols-def.def
+#objdump: -p
+
+#...
+.*\[[  ]*0\] sym1
+.*\[[  ]*1\] sym3
+.*\[[  ]*2\] sym5
+#pass
diff --git a/ld/testsuite/ld-pe/exclude-symbols-def-x86_64.s b/ld/testsuite/ld-pe/exclude-symbols-def-x86_64.s
new file mode 100644 (file)
index 0000000..2889de1
--- /dev/null
@@ -0,0 +1,11 @@
+.global sym1
+.global sym2
+.global sym3
+.global sym4
+.global sym5
+sym1:
+sym2:
+sym3:
+sym4:
+sym5:
+  ret
diff --git a/ld/testsuite/ld-pe/exclude-symbols-def.def b/ld/testsuite/ld-pe/exclude-symbols-def.def
new file mode 100644 (file)
index 0000000..c0cee7b
--- /dev/null
@@ -0,0 +1,4 @@
+LIBRARY exclude-symbols-def.dll
+EXCLUDE_SYMBOLS
+sym2
+sym4
index b640b0891f237b7b225271cb3453224759b20443..22819e0894f78a8c77ae1851d95a3afdf47e8a01 100644 (file)
@@ -127,3 +127,5 @@ run_ld_link_tests $foreign_sym_test
 
 run_dump_test "exclude-symbols-embedded-i386"
 run_dump_test "exclude-symbols-embedded-x86_64"
+run_dump_test "exclude-symbols-def-i386"
+run_dump_test "exclude-symbols-def-x86_64"