RO Elf program headers
Dimitry Andric
dim at FreeBSD.org
Sun Feb 23 22:17:11 UTC 2020
On 2020-02-23 16:31, Paul Floyd wrote:
> I’ve been working on getting Valgrind to work again on FreeBSD.
> Probably the biggest problem at the moment is that Valgrind doesn’t (yet) handle the read-only program headers.
> If I run “readelf -l libc++.so.1.0” on Linux I see two LOAD headers, the first one “R E” (read-execute) and the second one “RW” (read-write). If I do the same on FreeBSD then I see a third program header which is “R” (read-only), before the other two.
> My questions are
> - Does anyone know when this extra header was added? (I assume that it was added sometime in the past 5 years or so)
Most likely a very long time ago.
> - What is in these segments, and is it safe to assume that multiple shared libraries can map the same RO content to the same address?
If you use readelf -l, you will see a "Section to Segment mapping":
$ readelf -lW /usr/lib/libc++.so.1
Elf file type is DYN (Shared object file)
Entry point 0x5c000
There are 9 program headers, starting at offset 64
Program Headers:
Type Offset VirtAddr PhysAddr FileSiz MemSiz Flg Align
PHDR 0x000040 0x0000000000000040 0x0000000000000040 0x0001f8 0x0001f8 R 0x8
LOAD 0x000000 0x0000000000000000 0x0000000000000000 0x05b1d4 0x05b1d4 R 0x1000
LOAD 0x05c000 0x000000000005c000 0x000000000005c000 0x06bbe0 0x06bbe0 R E 0x1000
LOAD 0x0c8000 0x00000000000c8000 0x00000000000c8000 0x004c78 0x004c78 RW 0x1000
LOAD 0x0cd000 0x00000000000cd000 0x00000000000cd000 0x000de0 0x0032f8 RW 0x1000
DYNAMIC 0x0cc5c0 0x00000000000cc5c0 0x00000000000cc5c0 0x0001a0 0x0001a0 RW 0x8
GNU_RELRO 0x0c8000 0x00000000000c8000 0x00000000000c8000 0x004c78 0x004c78 R 0x1
GNU_EH_FRAME 0x046c34 0x0000000000046c34 0x0000000000046c34 0x003244 0x003244 R 0x4
GNU_STACK 0x000000 0x0000000000000000 0x0000000000000000 0x000000 0x000000 RW 0
Section to Segment mapping:
Segment Sections...
00
01 .dynsym .gnu.version .gnu.version_r .gnu.hash .hash .dynstr .rela.dyn .rela.plt .rodata .gcc_except_table .eh_frame_hdr .eh_frame
02 .text .init .fini .plt
03 .ctors .dtors .jcr .data.rel.ro .init_array .dynamic .got
04 .data .got.plt .bss
05 .dynamic
06 .ctors .dtors .jcr .data.rel.ro .init_array .dynamic .got
07 .eh_frame_hdr
08
E.g, segment 01 is R, and contains things like the dynamic symbol table, relocations, exception handling information, and so on. It is fairly safe to say that these can be shared.
-Dimitry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 223 bytes
Desc: Message signed with OpenPGP
URL: <http://lists.freebsd.org/pipermail/freebsd-toolchain/attachments/20200223/4192af38/attachment.sig>
More information about the freebsd-toolchain
mailing list