From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Reiser To: binutils@sourceware.cygnus.com Subject: optionally postpone assignment of Common Date: Tue, 25 Sep 2001 11:55:00 -0000 Message-id: <3BB0D3AC.16552408@BitWagon.com> References: <3B98EE77.3022801D@BitWagon.com> X-SW-Source: 2001-09/msg00452.html This patch against today's CVS add a new commandline option --no-define-common and corresponding script command INHIBIT_COMMON_ALLOCATION, which postpone the assignment of addresses for Common symbols. Tested on i386. If a Common block is left "dangling" (no allocation in some other module before runtime) then some existing rtld (such as Linux /lib/ld-2.1.3.so) allocate it in .text, but that is a problem that is outside of binutils. Index: ChangeLog =================================================================== RCS file: /cvs/src/src/ld/ChangeLog,v retrieving revision 1.490 diff -u -r1.490 ChangeLog --- ChangeLog 2001/09/24 21:16:47 1.490 +++ ChangeLog 2001/09/25 18:38:07 @@ -1,3 +1,13 @@ +2001-09-25 John Reiser + + * ldlang.c(lang_common): Conditionally inhibit Common allocation. + * lexsup.c: Add --no-define-common commandline option. + * ldgram.y: Add INHIBIT_COMMON_ALLOCATION script command. + * ldlex.l: Likewise. + * ld.h: Add command_line.inhibit_common_definition . + * ldmain.c(main): Initialize. + * ld.texinfo: Document. + 2001-09-24 Charles Wilson * pe-dll.c: Remove obsoleted declaration of Index: ld.h =================================================================== RCS file: /cvs/src/src/ld/ld.h,v retrieving revision 1.14 diff -u -r1.14 ld.h --- ld.h 2001/08/12 07:59:28 1.14 +++ ld.h 2001/09/25 18:30:49 @@ -102,6 +102,9 @@ typedef struct { /* 1 => assign space to common symbols even if `relocatable_output'. */ boolean force_common_definition; + + /* 1 => do not assign addresses to common symbols. */ + boolean inhibit_common_definition; boolean relax; /* Name of runtime interpreter to invoke. */ Index: ld.texinfo =================================================================== RCS file: /cvs/src/src/ld/ld.texinfo,v retrieving revision 1.51 diff -u -r1.51 ld.texinfo --- ld.texinfo 2001/09/24 18:35:08 1.51 +++ ld.texinfo 2001/09/25 18:30:56 @@ -950,6 +950,13 @@ symbol is defined, the first file listed is the location of the definition. The remaining files contain references to the symbol. +@cindex common allocation +@kindex --no-define-common +@item --no-define-common +This option inhibits the assignment of addresses to common symbols. +The script command @code{INHIBIT_COMMON_ALLOCATION} has the same effect. +@xref{Miscellaneous Commands}. + @cindex symbols, from command line @kindex --defsym @var{symbol}=@var{exp} @item --defsym @var{symbol}=@var{expression} @@ -2310,6 +2317,13 @@ This command has the same effect as the @samp{-d} command-line option: to make @code{ld} assign space to common symbols even if a relocatable output file is specified (@samp{-r}). + +@item INHIBIT_COMMON_ALLOCATION +@kindex INHIBIT_COMMON_ALLOCATION +@cindex common allocation in linker script +This command has the same effect as the @samp{--no-define-common} +command-line option: to make @code{ld} omit the assignment of addresses +to common symbols even for a non-relocatable output file. @item NOCROSSREFS(@var{section} @var{section} @dots{}) @kindex NOCROSSREFS(@var{sections}) Index: ldgram.y =================================================================== RCS file: /cvs/src/src/ld/ldgram.y,v retrieving revision 1.13 diff -u -r1.13 ldgram.y --- ldgram.y 2001/08/15 17:10:18 1.13 +++ ldgram.y 2001/09/25 18:30:57 @@ -125,6 +125,7 @@ %token SECTIONS PHDRS SORT %token '{' '}' %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH +%token INHIBIT_COMMON_ALLOCATION %token SIZEOF_HEADERS %token INCLUDE %token MEMORY DEFSYMEND @@ -321,6 +322,8 @@ { ldfile_set_output_arch($3); } | FORCE_COMMON_ALLOCATION { command_line.force_common_definition = true ; } + | INHIBIT_COMMON_ALLOCATION + { command_line.inhibit_common_definition = true ; } | INPUT '(' input_list ')' | GROUP { lang_enter_group (); } Index: ldlang.c =================================================================== RCS file: /cvs/src/src/ld/ldlang.c,v retrieving revision 1.62 diff -u -r1.62 ldlang.c --- ldlang.c 2001/09/19 05:33:33 1.62 +++ ldlang.c 2001/09/25 18:31:01 @@ -3553,6 +3553,8 @@ static void lang_common () { + if (command_line.inhibit_common_definition) + return; if (link_info.relocateable && ! command_line.force_common_definition) return; Index: ldlex.l =================================================================== RCS file: /cvs/src/src/ld/ldlex.l,v retrieving revision 1.6 diff -u -r1.6 ldlex.l --- ldlex.l 2001/09/19 05:33:33 1.6 +++ ldlex.l 2001/09/25 18:31:02 @@ -260,6 +260,7 @@ "CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);} "CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);} "FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);} +"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION);} "SECTIONS" { RTOKEN(SECTIONS);} "FILL" { RTOKEN(FILL);} "STARTUP" { RTOKEN(STARTUP);} Index: ldmain.c =================================================================== RCS file: /cvs/src/src/ld/ldmain.c,v retrieving revision 1.34 diff -u -r1.34 ldmain.c --- ldmain.c 2001/09/19 05:33:33 1.34 +++ ldmain.c 2001/09/25 18:31:03 @@ -205,6 +205,7 @@ config.split_by_reloc = (unsigned) -1; config.split_by_file = (bfd_size_type) -1; command_line.force_common_definition = false; + command_line.inhibit_common_definition = false; command_line.interpreter = NULL; command_line.rpath = NULL; command_line.warn_mismatch = true; Index: lexsup.c =================================================================== RCS file: /cvs/src/src/ld/lexsup.c,v retrieving revision 1.40 diff -u -r1.40 lexsup.c --- lexsup.c 2001/09/19 05:33:33 1.40 +++ lexsup.c 2001/09/25 18:31:05 @@ -132,6 +132,7 @@ #define OPTION_ALLOW_SHLIB_UNDEFINED (OPTION_TARGET_HELP + 1) #define OPTION_DISCARD_NONE (OPTION_ALLOW_SHLIB_UNDEFINED + 1) #define OPTION_SPARE_DYNAMIC_TAGS (OPTION_DISCARD_NONE + 1) +#define OPTION_NO_DEFINE_COMMON (OPTION_SPARE_DYNAMIC_TAGS + 1) /* The long options. This structure is used for both the option parsing and the help text. */ @@ -311,6 +312,8 @@ '\0', N_("SYMBOL"), N_("Call SYMBOL at load-time"), ONE_DASH }, { {"Map", required_argument, NULL, OPTION_MAP}, '\0', N_("FILE"), N_("Write a map file"), ONE_DASH }, + { {"no-define-common", no_argument, NULL, OPTION_NO_DEFINE_COMMON}, + '\0', NULL, N_("Do not define Common storage"), TWO_DASHES }, { {"no-demangle", no_argument, NULL, OPTION_NO_DEMANGLE }, '\0', NULL, N_("Do not demangle symbol names"), TWO_DASHES }, { {"no-keep-memory", no_argument, NULL, OPTION_NO_KEEP_MEMORY}, @@ -746,6 +749,9 @@ case 'n': config.magic_demand_paged = false; config.dynamic_link = false; + break; + case OPTION_NO_DEFINE_COMMON: + command_line.inhibit_common_definition = true; break; case OPTION_NO_DEMANGLE: demangling = false; -- John Reiser, jreiser@BitWagon.com