* 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.
This commit is contained in:
Alan Modra 2010-12-20 13:00:14 +00:00
parent e759c11602
commit 5c3049d2ef
19 changed files with 74 additions and 22 deletions

View File

@ -1,3 +1,22 @@
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

View File

@ -608,6 +608,8 @@ gld${EMULATION_NAME}_after_open (void)
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

View File

@ -133,6 +133,8 @@ gld${EMULATION_NAME}_before_allocation (void)
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.

View File

@ -376,6 +376,8 @@ gld_${EMULATION_NAME}_set_symbols (void)
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. */

View File

@ -1059,6 +1059,8 @@ gld${EMULATION_NAME}_after_open (void)
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;

View File

@ -35,6 +35,8 @@ gld${EMULATION_NAME}_after_open (void)
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

View File

@ -265,7 +265,7 @@ struct ld_emulation_xfer_struct ld_lnk960_emulation =
lnk960_syslib,
lnk960_hll,
lnk960_after_parse,
NULL, /* after_open */
after_open_default,
lnk960_after_allocation,
lnk960_set_output_arch,
lnk960_choose_target,

View File

@ -62,6 +62,8 @@ gld${EMULATION_NAME}_after_open (void)
{
bfd *abfd;
after_open_default ();
if (! command_line.embedded_relocs
|| link_info.relocatable)
return;

View File

@ -151,6 +151,7 @@ mmo_after_open (void)
is->the_bfd);
}
}
after_open_default ();
}
EOF

View File

@ -1219,6 +1219,8 @@ debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj)
static void
gld_${EMULATION_NAME}_after_open (void)
{
after_open_default ();
#ifdef DLL_SUPPORT
if (pe_dll_extra_pe_debug)
{

View File

@ -1151,6 +1151,8 @@ debug_section_p (bfd *abfd ATTRIBUTE_UNUSED, asection *sect, void *obj)
static void
gld_${EMULATION_NAME}_after_open (void)
{
after_open_default ();
is_underscoring ();
#ifdef DLL_SUPPORT
if (pep_dll_extra_pe_debug)

View File

@ -366,6 +366,8 @@ gld${EMULATION_NAME}_after_open (void)
{
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;

View File

@ -79,6 +79,8 @@ gldz80_after_open (void)
{
unsigned long mach_type;
after_open_default ();
switch (result_mach_type)
{
case M_Z80STRICT:

View File

@ -5503,17 +5503,17 @@ section relative symbols and for builtin functions that return an
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}.
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.
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,
In the following simple example,
@smallexample
@group
@ -5537,9 +5537,8 @@ address 0x100 in the first two assignments, then both @code{.} and
@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

View File

@ -226,6 +226,16 @@ after_parse_default (void)
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

View File

@ -553,7 +553,9 @@ fold_name (etree_type *tree)
" 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,
@ -700,7 +702,11 @@ exp_fold_tree_1 (etree_type *tree)
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;
@ -860,12 +866,6 @@ exp_fold_tree_1 (etree_type *tree)
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

View File

@ -127,6 +127,7 @@ struct ldexp_control {
/* 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. */

View File

@ -109,6 +109,7 @@ bfd_boolean delete_output_file_on_failure = FALSE;
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. */

View File

@ -469,6 +469,7 @@ extern bfd_boolean entry_from_cmdline;
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;