Bug 24769 - [RISCV] partial RELRO doesn't work: .got is not in PT_GNU_RELRO
Summary: [RISCV] partial RELRO doesn't work: .got is not in PT_GNU_RELRO
Status: UNCONFIRMED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.33
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-05 02:35 UTC by Fangrui Song
Modified: 2020-04-05 20:43 UTC (History)
1 user (show)

See Also:
Host:
Target: riscv*-*-*
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Fangrui Song 2019-07-05 02:35:04 UTC
% riscv64-linux-gnu-gcc -fuse-ld=bfd a.c -Wl,-z,relro -Wl,-Map,a.map -o a
% readelf -l a
....
   07     .preinit_array .init_array .fini_array .dynamic

Note .got is not in PT_GNU_RELRO.

In the link map, we can see that .got.plt is placed before .got, which is unusual (likely a bug).

% cat a.map
...
.got            0x0000000000002008       0x40
 *(.got.plt)
 .got.plt       0x0000000000002008       0x18 /path/to/riscv64-linux-gnu-gcc/usr/bin/../lib/gcc-cross/riscv64-linux-gnu/8/../../../../riscv64-linux-gnu/lib/Scrt1.o
 *(.igot.plt)
 *(.got)
 .got           0x0000000000002020       0x28 /path/to/riscv64-linux-gnu-gcc/usr/bin/../lib/gcc-cross/riscv64-linux-gnu/8/../../../../riscv64-linux-gnu/lib/Scrt1.o
                0x0000000000002020                _GLOBAL_OFFSET_TABLE_
 *(.igot)

The presence of .preinit_array (from Scrt1.o) is also weird.

% readelf -x .preinit_array a

Hex dump of section '.preinit_array':
  0x00001e08 00000000 00000000                   ........