PR27493, objcopy --weaken-symbol does not weaken undefined symbols

Alan Modra amodra@gmail.com
Wed Mar 3 07:15:14 GMT 2021


	PR 27493
	* objcopy.c (filter_symbols): Apply --weaken to undefined symbols.
	* NEWS: Mention feature.

diff --git a/binutils/NEWS b/binutils/NEWS
index d66944e95e..2e93100a38 100644
--- a/binutils/NEWS
+++ b/binutils/NEWS
@@ -1,5 +1,8 @@
 -*- text -*-
 
+* objcopy --weaken, --weaken-symbol and --weaken-symbols now make undefined
+  symbols weak on targets that support weak symbols.
+
 * Readelf and objdump can now display and use the contents of .debug_sup
   sections.
 
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 041aceaeef..99e6cad72e 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -1673,7 +1673,8 @@ filter_symbols (bfd *abfd, bfd *obfd, asymbol **osyms,
 
       if (keep)
 	{
-	  if ((flags & BSF_GLOBAL) != 0
+	  if (((flags & BSF_GLOBAL) != 0
+	       || undefined)
 	      && (weaken || is_specified_symbol (name, weaken_specific_htab)))
 	    {
 	      sym->flags &= ~ BSF_GLOBAL;

-- 
Alan Modra
Australia Development Lab, IBM


More information about the Binutils mailing list