and absolute symbols.
* ldemul.c (after_open_default): Look up __ld_compatibility.
* ldexp.c (fold_name): Convert absolute symbols to numbers when
inside output section definitions, or when __ld_compatibility >= 221.
(exp_fold_tree_1): Convert numbers to absolute when not in output
section definition and __ld_compatibility < 221. Don't always
convert values outside an output section definition to absolute.
* ldexp.h (uses_defined): Comment.
* ldlang.c (ld_compatibility): New variable.
* ldlang.h (ld_compatibility): Declare.
* emultempl/aix.em, * emultempl/armcoff.em, * emultempl/beos.em,
* emultempl/elf32.em, * emultempl/genelf.em, * emultempl/lnk960.em,
* emultempl/m68kcoff.em, * emultempl/mmo.em, * emultempl/pe.em,
* emultempl/pep.em, * emultempl/sunos.em, * emultempl/z80.em: Call
after_open_default from after_open function.
+2010-12-20 Alan Modra <amodra@gmail.com>
+
+ * ld.texinfo (Expression Section): Describe treatment of numbers
+ and absolute symbols.
+ * ldemul.c (after_open_default): Look up __ld_compatibility.
+ * ldexp.c (fold_name): Convert absolute symbols to numbers when
+ inside output section definitions, or when __ld_compatibility >= 221.
+ (exp_fold_tree_1): Convert numbers to absolute when not in output
+ section definition and __ld_compatibility < 221. Don't always
+ convert values outside an output section definition to absolute.
+ * ldexp.h (uses_defined): Comment.
+ * ldlang.c (ld_compatibility): New variable.
+ * ldlang.h (ld_compatibility): Declare.
+ * emultempl/aix.em, * emultempl/armcoff.em, * emultempl/beos.em,
+ * emultempl/elf32.em, * emultempl/genelf.em, * emultempl/lnk960.em,
+ * emultempl/m68kcoff.em, * emultempl/mmo.em, * emultempl/pe.em,
+ * emultempl/pep.em, * emultempl/sunos.em, * emultempl/z80.em: Call
+ after_open_default from after_open function.
+
2010-12-20 Alan Modra <amodra@gmail.com>
PR ld/12001
bfd_boolean r;
struct set_info *p;
+ after_open_default ();
+
/* Call ldctor_build_sets, after pretending that this is a
relocatable link. We do this because AIX requires relocation
entries for all references to symbols, even in a final
static void
gld${EMULATION_NAME}_after_open (void)
{
+ after_open_default ();
+
if (strstr (bfd_get_target (link_info.output_bfd), "arm") == NULL)
{
/* The arm backend needs special fields in the output hash structure.
static void
gld_${EMULATION_NAME}_after_open (void)
{
+ after_open_default ();
+
/* Pass the wacky PE command line options into the output bfd.
FIXME: This should be done via a function, rather than by
including an internal BFD header. */
struct bfd_link_needed_list *needed, *l;
struct elf_link_hash_table *htab;
+ after_open_default ();
+
htab = elf_hash_table (&link_info);
if (!is_elf_hash_table (htab))
return;
asection *sec;
asymbol **syms;
+ after_open_default ();
+
if (link_info.relocatable)
for (ibfd = link_info.input_bfds; ibfd != NULL; ibfd = ibfd->link_next)
if ((syms = bfd_get_outsymbols (ibfd)) != NULL
lnk960_syslib,
lnk960_hll,
lnk960_after_parse,
- NULL, /* after_open */
+ after_open_default,
lnk960_after_allocation,
lnk960_set_output_arch,
lnk960_choose_target,
{
bfd *abfd;
+ after_open_default ();
+
if (! command_line.embedded_relocs
|| link_info.relocatable)
return;
is->the_bfd);
}
}
+ after_open_default ();
}
EOF
static void
gld_${EMULATION_NAME}_after_open (void)
{
+ after_open_default ();
+
#ifdef DLL_SUPPORT
if (pe_dll_extra_pe_debug)
{
static void
gld_${EMULATION_NAME}_after_open (void)
{
+ after_open_default ();
+
is_underscoring ();
#ifdef DLL_SUPPORT
if (pep_dll_extra_pe_debug)
{
struct bfd_link_needed_list *needed, *l;
+ after_open_default ();
+
/* We only need to worry about this when doing a final link. */
if (link_info.relocatable || link_info.shared)
return;
{
unsigned long mach_type;
+ after_open_default ();
+
switch (result_mach_type)
{
case M_Z80STRICT:
address, such as @code{ADDR}, @code{LOADADDR}, @code{ORIGIN} and
@code{SEGMENT_START}. Other terms are simply numbers, or are builtin
functions that return a non-address value, such as @code{LENGTH}.
-
-When the linker evaluates an expression, the result depends on where
-the expression is located in a linker script. Expressions appearing
-outside an output section definitions are evaluated with all terms
-first being converted to absolute addresses before applying operators,
-and evaluate to an absolute address result. Expressions appearing
-inside an output section definition are evaluated with more complex
-rules, but the aim is to treat terms as relative addresses and produce
-a relative address result. In particular, an assignment of a number
-to a symbol results in a symbol relative to the output section with an
-offset given by the number. So, in the following simple example,
+One complication is that unless you assign @code{__ld_compatibility}
+a value of 221 or larger, numbers and absolute symbols are treated
+differently depending on their location, for compatibility with older
+versions of @code{ld}. Expressions appearing outside an output
+section definition treat all numbers as absolute addresses.
+Expressions appearing inside an output section definition treat
+absolute symbols as numbers. If @code{__ld_compatibility} is assigned
+a value larger than 221, then absolute symbols and numbers are simply
+treated as numbers everywhere.
+
+In the following simple example,
@smallexample
@group
@code{__data_start} are set to 0x10 relative to the @code{.data}
section in the second two assignments.
-For expressions appearing inside an output section definition
-involving numbers, relative addresses and absolute addresses, ld
-follows these rules to evaluate terms:
+For expressions involving numbers, relative addresses and absolute
+addresses, ld follows these rules to evaluate terms:
@itemize @bullet
@item
void
after_open_default (void)
{
+ struct bfd_link_hash_entry *h;
+
+ h = bfd_wrapped_link_hash_lookup (link_info.output_bfd,
+ &link_info,
+ "__ld_compatibility",
+ FALSE, FALSE, TRUE);
+ if (h != NULL
+ && (h->type == bfd_link_hash_defined
+ || h->type == bfd_link_hash_defweak))
+ ld_compatibility = h->u.def.value;
}
void
" referenced in expression\n"),
tree->name.name);
}
- else if (output_section == bfd_abs_section_ptr)
+ else if (output_section == bfd_abs_section_ptr
+ && (expld.section != bfd_abs_section_ptr
+ || ld_compatibility >= 221))
new_number (h->u.def.value + h->u.def.section->output_offset);
else
new_rel (h->u.def.value + h->u.def.section->output_offset,
switch (tree->type.node_class)
{
case etree_value:
- new_number (tree->value.value);
+ if (expld.section == bfd_abs_section_ptr
+ && ld_compatibility < 221)
+ new_abs (tree->value.value);
+ else
+ new_number (tree->value.value);
expld.result.str = tree->value.str;
break;
memset (&expld.result, 0, sizeof (expld.result));
break;
}
-
- /* Any value not inside an output section statement is an
- absolute value. */
- if (expld.result.valid_p
- && expld.section == bfd_abs_section_ptr)
- make_abs ();
}
void
/* Working results. */
etree_value_type result;
bfd_vma dot;
+ /* Set if an expression contains DEFINED(). */
bfd_boolean uses_defined;
/* Current dot and section passed to ldexp folder. */
struct lang_phdr *lang_phdr_list;
struct lang_nocrossrefs *nocrossref_list;
bfd_boolean missing_file = FALSE;
+int ld_compatibility;
/* Functions that traverse the linker script and might evaluate
DEFINED() need to increment this. */
extern lang_statement_list_type file_chain;
extern lang_statement_list_type input_file_chain;
+extern int ld_compatibility;
extern int lang_statement_iteration;
extern bfd_boolean missing_file;