Skip to content

[LTO][PIC][ARM][SSP] extra indirection accessing __stack_chk_guard #64999

Closed
@wolfy1961

Description

@wolfy1961

After commit e018cbf7208b we're seeing segfaults when accessing __stack_chk_guard when using LTO. I'm attaching a small test case (3 source files and small build script) that shows the problem). When compiling with -flto -fPIC and linking without any additional flags, we're seeing the following code in the function foo:

201dc: e59f006c      ldr     r0, [pc, #0x6c]         @ 0x20250 <foo+0x80>
201e0: e5900000      ldr     r0, [r0]
201e4: e5900000      ldr     r0, [r0]
201e8: e50b000c      str     r0, [r11, #-0xc]
...
20250: 54 02 03 00   .word   0x00030254

And from the linker map file:

30254    30254        4     1                 __stack_chk_guard

So we're seeing an extra indirection, causing the segfaults.

If we're adding -pie to the link line, things work fine. We see:

   10280: e59f0074      ldr     r0, [pc, #0x74]         @ 0x102fc <foo+0x88>
   10284: e08f0000      add     r0, pc, r0
   10288: e5900000      ldr     r0, [r0]
   1028c: e5900000      ldr     r0, [r0]
    ...
   102fc: e4 00 01 00   .word   0x000100e4

with the GOT present in the executable.

Note that the the test case is not meant to execute anywhere. A rudimentary module (rt.c) supplies the missing definitions.
stack_check.zip

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions