llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.03k stars 11.97k forks source link

-mlong-calls generates non-PIC code on ARM #39970

Open glandium opened 5 years ago

glandium commented 5 years ago
Bugzilla Link 40624
Version unspecified
OS Linux
CC @froydnj

Extended Description

With the following source:

extern __attribute__((visibility("hidden"))) int foo();

int bar() { return foo(); };

clang generates the following with -fPIC -mlong-calls -O3 --target=armv7a-linux-gnueabi:

bar:
        ldr     r0, .LCPI0_0
        bx      r0
.LCPI0_0:
        .long   foo

That is not PIC, as that .LCPI0_0 label is in .text.

GCC generates the following:

bar:
        ldr     r3, .L3
.LPIC0:
        add     r3, pc, r3
        bx      r3
.L3:
        .word   foo-(.LPIC0+8)

(All courtesy of godbolt)

https://godbolt.org/z/gKwbiO

llvmbot commented 4 months ago

@llvm/issue-subscribers-backend-arm

Author: Mike Hommey (glandium)

| | | | --- | --- | | Bugzilla Link | [40624](https://llvm.org/bz40624) | | Version | unspecified | | OS | Linux | | CC | @froydnj | ## Extended Description With the following source: ``` extern __attribute__((visibility("hidden"))) int foo(); int bar() { return foo(); }; ``` clang generates the following with -fPIC -mlong-calls -O3 --target=armv7a-linux-gnueabi: ``` bar: ldr r0, .LCPI0_0 bx r0 .LCPI0_0: .long foo ``` That is not PIC, as that .LCPI0_0 label is in .text. GCC generates the following: ``` bar: ldr r3, .L3 .LPIC0: add r3, pc, r3 bx r3 .L3: .word foo-(.LPIC0+8) ``` (All courtesy of godbolt) https://godbolt.org/z/gKwbiO