* 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-29 Alan Modra <amodra@bigpond.net.au>
+2001-09-29 John Reiser <jreiser@BitWagon.com>
- * ldlang.c (section_already_linked): Remove assignment to kept_section.
+ * 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-26 Alan Modra <amodra@bigpond.net.au>
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. */
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}.
+
+The @samp{--no-define-common} option allows decoupling
+the decision to assign addresses to Common symbols from the choice
+of the output file type; otherwise a non-Relocatable output type
+forces assigning addresses to Common symbols.
+Using @samp{--no-define-common} allows Common symbols that are referenced
+from a shared library to be assigned addresses only in the main program.
+This eliminates the unused duplicate space in the shared library,
+and also prevents any possible confusion over resolving to the wrong
+duplicate when there are many dynamic modules with specialized search
+paths for runtime symbol resolution.
+
@cindex symbols, from command line
@kindex --defsym @var{symbol}=@var{exp}
@item --defsym @var{symbol}=@var{expression}
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})
@cindex cross references
%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
{ 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 (); }
static void
lang_common ()
{
+ if (command_line.inhibit_common_definition)
+ return;
if (link_info.relocateable
&& ! command_line.force_common_definition)
return;
<BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS" { RTOKEN(CREATE_OBJECT_SYMBOLS);}
<BOTH,SCRIPT>"CONSTRUCTORS" { RTOKEN( CONSTRUCTORS);}
<BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION" { RTOKEN(FORCE_COMMON_ALLOCATION);}
+<BOTH,SCRIPT>"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION);}
<BOTH,SCRIPT>"SECTIONS" { RTOKEN(SECTIONS);}
<BOTH,SCRIPT>"FILL" { RTOKEN(FILL);}
<BOTH,SCRIPT>"STARTUP" { RTOKEN(STARTUP);}
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;
#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. */
'\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},
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;
break;