Bug 21252 - -shared/-pie create RWE LOAD segment
Summary: -shared/-pie create RWE LOAD segment
Status: NEW
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.29
: P2 normal
Target Milestone: 2.40
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-15 20:40 UTC by H.J. Lu
Modified: 2024-02-29 21:02 UTC (History)
1 user (show)

See Also:
Host:
Target: hppa64-linux
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description H.J. Lu 2017-03-15 20:40:56 UTC
hjl@gnu-mic-2 ld]$ cat x.s
	.text
	.global start	/* Used by SH targets.  */
start:
	.global _start
_start:
	.global __start
__start:
	.global main	/* Used by HPPA targets.  */
main:
	.dc.a 0
	.data
	.byte 2
[hjl@gnu-mic-2 ld]$ ../gas/as-new -o x.o x.s
[hjl@gnu-mic-2 ld]$ ./ld-new -shared x.o
[hjl@gnu-mic-2 ld]$ ../binutils/readelf -SWl a.out 
There are 10 section headers, starting at offset 0x14e8:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .dynamic          DYNAMIC         00000000000000e8 0000e8 0000e0 10  WA  4   0  8
  [ 2] .hash             HASH            00000000000001c8 0001c8 000034 04   A  3   0  8
  [ 3] .dynsym           DYNSYM          0000000000000200 000200 0000c0 18   A  4   1  8
  [ 4] .dynstr           STRTAB          00000000000002c0 0002c0 000026 00   A  0   0  1
  [ 5] .text             PROGBITS        00000000000002e8 0002e8 000008 00  AX  0   0  8
  [ 6] .data             PROGBITS        00000000000012f0 0012f0 000011 00  WA  0   0  1
  [ 7] .symtab           SYMTAB          0000000000000000 001308 000168 18      8   8  8
  [ 8] .strtab           STRTAB          0000000000000000 001470 00002f 00      0   0  1
  [ 9] .shstrtab         STRTAB          0000000000000000 00149f 000046 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  p (processor specific)

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

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  PHDR           0x000040 0x0000000000000040 0x0000000000000000 0x0000a8 0x0000a8 R E 0x8
  LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x001301 0x001301 RWE 0x1000
  DYNAMIC        0x0000e8 0x00000000000000e8 0x00000000000000e8 0x0000e0 0x0000e0 RW  0x8

 Section to Segment mapping:
  Segment Sections...
   00     
   01     .dynamic .hash .dynsym .dynstr .text .data 
   02     .dynamic 
[hjl@gnu-mic-2 ld]$  

I was expecting

  LOAD           0x000000 0x0000000000010000 0x0000000000010000 0x0000f0 0x0000f0 R E 0x1000
  LOAD           0x0000f0 0x00000000000110f0 0x00000000000110f0 0x000011 0x000011 RW  0x1000
Comment 1 H.J. Lu 2023-01-23 16:50:23 UTC
Works for binutils 2.40:

There are 13 section headers, starting at offset 0x3118:

Section Headers:
  [Nr] Name              Type            Address          Off    Size   ES Flg Lk Inf Al
  [ 0]                   NULL            0000000000000000 000000 000000 00      0   0  0
  [ 1] .hash             HASH            0000000000000200 000200 000028 04   A  3   0  8
  [ 2] .gnu.hash         GNU_HASH        0000000000000228 000228 000034 00   A  3   0  8
  [ 3] .dynsym           DYNSYM          0000000000000260 000260 000078 18   A  4   1  8
  [ 4] .dynstr           STRTAB          00000000000002d8 0002d8 00000e 00   A  0   0  1
  [ 5] .text             PROGBITS        0000000000001000 001000 000008 00  AX  0   0  1
  [ 6] .note.gnu.property NOTE            0000000000002000 002000 000030 00   A  0   0  8
  [ 7] .eh_frame         PROGBITS        0000000000002030 002030 000000 00   A  0   0  8
  [ 8] .dynamic          DYNAMIC         0000000000003f40 002f40 0000c0 10  WA  4   0  8
  [ 9] .data             PROGBITS        0000000000004000 003000 000001 00  WA  0   0  1
  [10] .symtab           SYMTAB          0000000000000000 003008 000090 18     11   2  8
  [11] .strtab           STRTAB          0000000000000000 003098 000017 00      0   0  1
  [12] .shstrtab         STRTAB          0000000000000000 0030af 000067 00      0   0  1
Key to Flags:
  W (write), A (alloc), X (execute), M (merge), S (strings), I (info),
  L (link order), O (extra OS processing required), G (group), T (TLS),
  C (compressed), x (unknown), o (OS specific), E (exclude),
  D (mbind), l (large), p (processor specific)

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

Program Headers:
  Type           Offset   VirtAddr           PhysAddr           FileSiz  MemSiz   Flg Align
  LOAD           0x000000 0x0000000000000000 0x0000000000000000 0x0002e6 0x0002e6 R   0x1000
  LOAD           0x001000 0x0000000000001000 0x0000000000001000 0x000008 0x000008 R E 0x1000
  LOAD           0x002000 0x0000000000002000 0x0000000000002000 0x000030 0x000030 R   0x1000
  LOAD           0x002f40 0x0000000000003f40 0x0000000000003f40 0x0000c1 0x0000c1 RW  0x1000
  DYNAMIC        0x002f40 0x0000000000003f40 0x0000000000003f40 0x0000c0 0x0000c0 RW  0x8
  NOTE           0x002000 0x0000000000002000 0x0000000000002000 0x000030 0x000030 R   0x8
  GNU_PROPERTY   0x002000 0x0000000000002000 0x0000000000002000 0x000030 0x000030 R   0x8
  GNU_RELRO      0x002f40 0x0000000000003f40 0x0000000000003f40 0x0000c0 0x0000c0 R   0x1

 Section to Segment mapping:
  Segment Sections...
   00     .hash .gnu.hash .dynsym .dynstr 
   01     .text 
   02     .note.gnu.property 
   03     .dynamic .data 
   04     .dynamic 
   05     .note.gnu.property 
   06     .note.gnu.property 
   07     .dynamic
Comment 2 Alan Modra 2024-02-29 21:02:58 UTC
(In reply to H.J. Lu from comment #1)
> Works for binutils 2.40:
Not for hppa64-linux.  The RWE load segment is due to placing .dynamic at the start of the text segment.  .dynamic is read/write.