Bug 23561 - linux x86_64: ELF PHDR not mapped
Summary: linux x86_64: ELF PHDR not mapped
Status: RESOLVED DUPLICATE of bug 23428
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.31
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-08-22 10:32 UTC by Felix von Leitner
Modified: 2020-01-13 12:16 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed:
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Felix von Leitner 2018-08-22 10:32:37 UTC
I'm using gcc 8.2.0 with binutils 2.31.1 to build my dietlibc (www.fefe.de/dietlibc/, use CVS version to reproduce).

Part of the startup code of my libc goes through auxvec to find PT_TLS and then initialize the thread local storage.

Now, this code worked fine for years. When I make clean and build with the above mentioned versions, I get a segfault in the AT_PHDR traversal, because AT_PHDR points to 0x400040 but /proc/pid/maps says:

00401000-00404000 r-xp 00001000 08:12 19664433

And indeed, readelf on the binary shows that:

Program Headers:
  Type           Offset             VirtAddr           PhysAddr
                 FileSiz            MemSiz              Flags  Align
  LOAD           0x0000000000001000 0x0000000000401000 0x0000000000401000
                 0x00000000000021e7 0x00000000000021e7  R E    0x1000

So the kernel did as it was told and loaded starting from 1000.

My current understanding is that I did it right and this is a bug in binutils to put the wrong value in the ELF header. Am I wrong? How else am I supposed to access the PHDR? Or maybe I am supposed to find the thread local storage data some other way?

Please advise.
Comment 1 H.J. Lu 2018-08-22 12:51:02 UTC
Dup.

*** This bug has been marked as a duplicate of bug 23428 ***
Comment 2 Sourceware Commits 2020-01-13 12:16:43 UTC
The master branch has been updated by Alan Modra <amodra@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a788aedd86da983faf0afef3cb41461118a2e9f2

commit a788aedd86da983faf0afef3cb41461118a2e9f2
Author: Alan Modra <amodra@gmail.com>
Date:   Mon Jan 13 22:30:46 2020 +1030

    PR23560, PR23561, readelf memory leaks
    
    	PR 23560
    	PR 23561
    	* dwarf.c (display_debug_frames): Move fde_fc earlier.  Free
    	fde_fc col_type and col_offset.
    	* readelf.c (apply_relocations): Move symsec check earlier.
    	(free_debug_section): Free reloc_info.
    	(process_notes_at): Free pnotes on error path.
    	(process_object): Free dump_sects here..
    	(process_archive): ..not here.