This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH] ld: provide __ehdr_start magic symbol
- From: Alan Modra <amodra at gmail dot com>
- To: Roland McGrath <mcgrathr at google dot com>
- Cc: binutils at sourceware dot org, Mark Seaborn <mseaborn at google dot com>
- Date: Wed, 20 Jun 2012 11:59:55 +0930
- Subject: Re: [PATCH] ld: provide __ehdr_start magic symbol
- References: <x57ja9zzf0tu.fsf@frobland.mtv.corp.google.com>
On Tue, Jun 19, 2012 at 02:28:45PM -0700, Roland McGrath wrote:
> + if (hdrs_segment != NULL && link_info != NULL)
> + {
> + /* There is a segment that contains both the file headers and the
> + program headers, so provide a symbol __ehdr_start pointing there.
> + A program can use this to examine itself robustly. */
> +
> + struct elf_link_hash_entry *hash
> + = elf_link_hash_lookup (elf_hash_table (link_info), "__ehdr_start",
> + FALSE, FALSE, TRUE);
> + if (hash != NULL
> + && (hash->root.type == bfd_link_hash_new
> + || hash->root.type == bfd_link_hash_undefined
> + || hash->root.type == bfd_link_hash_undefweak
> + || hash->root.type == bfd_link_hash_common))
For other linker PROVIDEd symbols, we don't test for undefweak. ie. a
weak reference stays undefined.
> + {
> + hash->root.type = bfd_link_hash_defined;
> + hash->root.u.def.value = filehdr_vaddr;
> + hash->root.u.def.section = bfd_abs_section_ptr;
I've just recently changed a lot of places where the linker defines
symbols that hold a virtual address to *not* use absolute symbols.
Absolute syms shouldn't be relocated by ld.so. They are currently,
but if this is ever fixed your __ehdr_start sym won't relocate when a
shared lib or pie is loaded at some address other than the one it was
linked at.
Maybe
if (hdrs_segment->count != 0)
{
asection *s = hdrs_segment->sections[0];
hash->root.u.def.value = filehdr_vaddr - s->vma;
hash->root.u.def.section = s;
}
and look through other elf_segment_map entries for the lowest vma
section if you happen to have ehdr in a segment by itself, falling
back to bfd_abs_section_ptr if there are no sections.
> + hash->def_regular = 1;
> + hash->non_elf = 0;
> + }
> + }
> +
--
Alan Modra
Australia Development Lab, IBM