This is an archive of the discontinued LLVM Phabricator instance.

[ARM] [ELF] Fix ARMMaterializeGV for Indirect calls
ClosedPublic

Authored by zatrazz on Jan 25 2021, 10:43 AM.

Details

Summary

Recent shouldAssumeDSOLocal changes (introduced by 961f31d8ad14c66)
do not take in consideration the relocation model anymore. The ARM
fast-isel pass uses the function return to set whether a global symbol
is loaded indirectly or not, and without the expected information
llvm now generates an extra load for following code:

$ cat test.ll
@__asan_option_detect_stack_use_after_return = external global i32
define dso_local i32 @main(i32 %argc, i8** %argv) #0 {
entry:
  %0 = load i32, i32* @__asan_option_detect_stack_use_after_return,
align 4
  %1 = icmp ne i32 %0, 0
  br i1 %1, label %2, label %3

2:
  ret i32 0

3:
  ret i32 1
}

attributes #0 = { noinline optnone }

$ lcc test.ll -o -
[...]
main:
        .fnstart
[...]
        movw    r0, :lower16:__asan_option_detect_stack_use_after_return
        movt    r0, :upper16:__asan_option_detect_stack_use_after_return
        ldr     r0, [r0]
        ldr     r0, [r0]
        cmp     r0, #0
[...]

And without 'optnone' it produces:

[...]
main:
        .fnstart
[...]
        movw    r0, :lower16:__asan_option_detect_stack_use_after_return
        movt    r0, :upper16:__asan_option_detect_stack_use_after_return
        ldr     r0, [r0]
        clz     r0, r0
        lsr     r0, r0, #5
        bx      lr

[...]

This triggered a lot of invalid memory access in sanitizers for
arm-linux-gnueabihf. I checked this patch both a stage1 built with
gcc and a stage2 bootstrap and it fixes all the Linux sanitizers
issues.

Diff Detail

Event Timeline

zatrazz created this revision.Jan 25 2021, 10:43 AM
zatrazz requested review of this revision.Jan 25 2021, 10:43 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2021, 10:43 AM
MaskRay edited the summary of this revision. (Show Details)Jan 25 2021, 10:50 AM
MaskRay accepted this revision.EditedJan 25 2021, 10:53 AM

Thanks!

We could make -fdirect-access-external-data create a module metadata to make declarations automatically dso_local, but I am not sure that is useful (can cause copy relocations/canonical PLT entries if the symbol is defined externally)

This revision is now accepted and ready to land.Jan 25 2021, 10:53 AM
This revision was landed with ongoing or failed builds.Jan 26 2021, 10:58 AM
This revision was automatically updated to reflect the committed changes.