This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: symbols defined in discarded sections


On Fri, Dec 20, 2002 at 09:32:07AM +1030, Alan Modra wrote:
> Currently, ld emits global symbols defined in discarded sections,
> turning them into absolute syms.  I think this is the wrong thing
> to do, and that such symbols should be stripped.  Opinions?

Like this.

include/ChangeLog
	* bfdlink.h (struct bfd_link_info): Add "strip_discarded".

bfd/ChangeLog
	* elflink.h (elf_link_output_extsym): Heed strip_discarded.

ld/ChangeLog
	* ldmain.c (main): Init "strip_discarded".
	* lexsup.c (OPTION_STRIP_DISCARDED): Define.
	(OPTION_NO_STRIP_DISCARDED): Define.
	(ld_options): Add "strip-discarded" and "no-strip-discarded".
	(parse_args): Handle them.

Index: include/bfdlink.h
===================================================================
RCS file: /cvs/src/src/include/bfdlink.h,v
retrieving revision 1.25
diff -u -p -r1.25 bfdlink.h
--- include/bfdlink.h	19 Dec 2002 23:05:39 -0000	1.25
+++ include/bfdlink.h	19 Dec 2002 23:13:23 -0000
@@ -285,6 +285,9 @@ struct bfd_link_info
      should be created.  */
   unsigned int eh_frame_hdr: 1;
 
+  /* TRUE if global symbols in discarded sections should be stripped.  */
+  unsigned int strip_discarded: 1;
+
   /* Which symbols to strip.  */
   enum bfd_link_strip strip;
 
Index: bfd/elflink.h
===================================================================
RCS file: /cvs/src/src/bfd/elflink.h,v
retrieving revision 1.201
diff -u -p -r1.201 elflink.h
--- bfd/elflink.h	12 Dec 2002 10:26:01 -0000	1.201
+++ bfd/elflink.h	19 Dec 2002 23:13:27 -0000
@@ -6123,11 +6123,16 @@ elf_link_output_extsym (h, data)
 	   && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0
 	   && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0)
     strip = TRUE;
-  else if (finfo->info->strip == strip_all
-	   || (finfo->info->strip == strip_some
-	       && bfd_hash_lookup (finfo->info->keep_hash,
-				   h->root.root.string,
-				   FALSE, FALSE) == NULL))
+  else if (finfo->info->strip == strip_all)
+    strip = TRUE;
+  else if (finfo->info->strip == strip_some
+	   && bfd_hash_lookup (finfo->info->keep_hash,
+			       h->root.root.string, FALSE, FALSE) == NULL)
+    strip = TRUE;
+  else if (finfo->info->strip_discarded
+	   && (h->root.type == bfd_link_hash_defined
+	       || h->root.type == bfd_link_hash_defweak)
+	   && elf_discarded_section (h->root.u.def.section))
     strip = TRUE;
   else
     strip = FALSE;
Index: ld/ldmain.c
===================================================================
RCS file: /cvs/src/src/ld/ldmain.c,v
retrieving revision 1.55
diff -u -p -r1.55 ldmain.c
--- ld/ldmain.c	19 Dec 2002 23:11:19 -0000	1.55
+++ ld/ldmain.c	19 Dec 2002 23:13:28 -0000
@@ -247,6 +247,7 @@ main (argc, argv)
   link_info.new_dtags = FALSE;
   link_info.combreloc = TRUE;
   link_info.eh_frame_hdr = FALSE;
+  link_info.strip_discarded = TRUE;
   link_info.strip = strip_none;
   link_info.discard = discard_sec_merge;
   link_info.common_skip_ar_aymbols = bfd_link_common_skip_none;
Index: ld/lexsup.c
===================================================================
RCS file: /cvs/src/src/ld/lexsup.c,v
retrieving revision 1.56
diff -u -p -r1.56 lexsup.c
--- ld/lexsup.c	30 Nov 2002 08:39:45 -0000	1.56
+++ ld/lexsup.c	19 Dec 2002 23:13:29 -0000
@@ -133,6 +133,8 @@ int parsing_defsym = 0;
 #define OPTION_NO_DEFINE_COMMON		(OPTION_SPARE_DYNAMIC_TAGS + 1)
 #define OPTION_NOSTDLIB			(OPTION_NO_DEFINE_COMMON + 1)
 #define OPTION_NO_OMAGIC		(OPTION_NOSTDLIB + 1)
+#define OPTION_STRIP_DISCARDED		(OPTION_NO_OMAGIC + 1)
+#define OPTION_NO_STRIP_DISCARDED	(OPTION_STRIP_DISCARDED + 1)
 
 /* The long options.  This structure is used for both the option
    parsing and the help text.  */
@@ -239,6 +241,10 @@ static const struct ld_option ld_options
       's', NULL, N_("Strip all symbols"), TWO_DASHES },
   { {"strip-debug", no_argument, NULL, 'S'},
       'S', NULL, N_("Strip debugging symbols"), TWO_DASHES },
+  { {"strip-discarded", no_argument, NULL, OPTION_STRIP_DISCARDED},
+      '\0', NULL, N_("Strip symbols in discarded sections"), TWO_DASHES },
+  { {"no-strip-discarded", no_argument, NULL, OPTION_NO_STRIP_DISCARDED},
+      '\0', NULL, N_("Do not strip symbols in discarded sections"), TWO_DASHES },
   { {"trace", no_argument, NULL, 't'},
       't', NULL, N_("Trace file opens"), TWO_DASHES },
   { {"script", required_argument, NULL, 'T'},
@@ -917,6 +923,12 @@ parse_args (argc, argv)
 	  break;
 	case 's':
 	  link_info.strip = strip_all;
+	  break;
+	case OPTION_STRIP_DISCARDED:
+	  link_info.strip_discarded = TRUE;
+	  break;
+	case OPTION_NO_STRIP_DISCARDED:
+	  link_info.strip_discarded = FALSE;
 	  break;
 	case OPTION_SHARED:
 	  if (config.has_shared)


-- 
Alan Modra
IBM OzLabs - Linux Technology Centre


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]