I am trying to compile with -msecure-plt, and although compilation is completing just fine, when looking at the memory maps it doesn't look like the flag is actually doing anything. I am assuming it is not doing anything because the got and plt sections are both still in RWXP
segements.
Dump of assembler code for function main:
0x1000061c <+0>: stwu r1,-16(r1)
0x10000620 <+4>: mflr r0
0x10000624 <+8>: stw r0,20(r1)
0x10000628 <+12>: stw r31,12(r1)
0x1000062c <+16>: mr r31,r1
0x10000630 <+20>: bl 0x1001096c <libfunc@plt>
0x10000634 <+24>: mr r10,r3
0x10000638 <+28>: lis r9,4096
0x1000063c <+32>: addi r3,r9,2048
0x10000640 <+36>: mr r4,r10
0x10000644 <+40>: crclr 4*cr1+eq
0x10000648 <+44>: bl 0x10010964 <printf@plt>
=> 0x1000064c <+48>: li r9,1
0x10000650 <+52>: mr r3,r9
0x10000654 <+56>: addi r11,r31,16
0x10000658 <+60>: lwz r0,4(r11)
0x1000065c <+64>: mtlr r0
0x10000660 <+68>: lwz r31,-4(r11)
0x10000664 <+72>: mr r1,r11
0x10000668 <+76>: blr
with /proc/<pid>/maps
showing a memory map of
00100000-00103000 r-xp 00000000 00:00 0 [vdso]
0fe40000-0ffb8000 r-xp 00000000 00:01 6285 /lib/libc-2.22.so
0ffb8000-0ffc7000 ---p 00178000 00:01 6285 /lib/libc-2.22.so
0ffc7000-0ffc9000 r--p 00177000 00:01 6285 /lib/libc-2.22.so
0ffc9000-0ffcd000 rwxp 00179000 00:01 6285 /lib/libc-2.22.so
0ffcd000-0ffcf000 rwxp 00000000 00:00 0
0ffdf000-0ffe0000 r-xp 00000000 00:01 5928 /lib/libmaintest.so
0ffe0000-0ffef000 ---p 00001000 00:01 5928 /lib/libmaintest.so
0ffef000-0fff0000 rwxp 00000000 00:01 5928 /lib/libmaintest.so
10000000-10001000 r-xp 00000000 00:01 5934 /root/main
10010000-10011000 rwxp 00000000 00:01 5934 /root/main
b7860000-b7882000 r-xp 00000000 00:01 6240 /lib/ld-2.22.so
b7890000-b7892000 rw-p 00000000 00:00 0
b7892000-b7893000 r--p 00022000 00:01 6240 /lib/ld-2.22.so
b7893000-b7895000 rwxp 00023000 00:01 6240 /lib/ld-2.22.so
bff1a000-bff3b000 rw-p 00000000 00:00 0 [stack]
which sticks both of the plot jumps right into the middle of a rwx
section. Am I misinterpreting this information?
I think that might be a kernel limitation: see e.g. https://lkml.org/lkml/2016/8/8/354 - it looks like the kernel maps things in ways you wouldn't expect for what I understand to be historical reasons.
It may be changing soon, given that the patch above was sent yesterday.