Linker option separate-loadable-segments not available in linker

Juan Yescas jyescas@google.com
Fri Sep 20 06:23:01 GMT 2024


Hi Binutils team,

There is a linker flag in clang *Wl,-z,separate-loadable-segments* that
generates LOAD segments with this characteristic:

- file offsets for the LOAD segments are aligned at max-page-size

This flag does not seem to be available in GNU linker. Is it under a
different name? The closest one that I found is *Wl-z,separate-code*.

An example of the functionality of the flag is below. The binary is linked
with *Wl,-z,separate-loadable-segments* and *Wl,-z,max-page-size=16384*

readelf -l /lib64/mylibrary.so


Elf file type is DYN (Shared object file)
Entry point 0
There are 11 program headers, starting at offset 64

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz
MemSiz  Flg Align
  PHDR           0x000040 0x0000000000000040 0x0000000000000040 0x00268
0x00268 R   0x8
  LOAD           *0x000000* 0x0000000000000000 0x0000000000000000 0x4380c
0x4380c R   *0x4000*
  LOAD           *0x044000* 0x0000000000044000 0x0000000000044000 0x960a0
0x960a0 R E *0x4000*
  LOAD           *0x0dc000* 0x00000000000dc000 0x00000000000dc000 0x03e58
0x04000 RW  *0x4000*
  LOAD           *0x0e0000* 0x00000000000e0000 0x00000000000e0000 0x005a0
0x23560 RW  *0x4000*
  TLS            0x0dc000 0x00000000000dc000 0x00000000000dc000 0x00008
0x00008 R   0x8
  DYNAMIC        0x0dea68 0x00000000000dea68 0x00000000000dea68 0x001c0
0x001c0 RW  0x8
  GNU_RELRO      0x0dc000 0x00000000000dc000 0x00000000000dc000 0x03e58
0x04000 R   0x1
  GNU_EH_FRAME   0x027e58 0x0000000000027e58 0x0000000000027e58 0x047b4
0x047b4 R   0x4
  GNU_STACK      0x000000 0x0000000000000000 0x0000000000000000 0x00000
0x00000 RW  0
  NOTE           0x0002a8 0x00000000000002a8 0x00000000000002a8 0x00050
0x00050 R   0x4


The reason that library requires this format is:

- Developers use /proc/<id>/maps to read/write the segments and when they
access areas that are not
*file backed*, they get SIGBUS.

 If the binaries are linked with *Wl,-z,separate-loadable-segments *the
SIGBUS won't happen.

Could you please let me know if there is a similar flag available?

Thanks in advance
Juan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/binutils/attachments/20240920/6a359bfd/attachment.htm>


More information about the Binutils mailing list