llvm / llvm-project

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

No relocation are emitted for pointer on weak function for arm #112340

Open Ralender opened 5 days ago

Ralender commented 5 days ago

Make file with the following named tmp.c

int __attribute__((weak)) foo() { return 9; }

typedef int (*func_ptr)();

func_ptr get() { return &foo; }

run:

clang -target arm-none-linux-android tmp.c -c -o out.o
llvm-objdump -r out.o

The function pointer in get may get overridden by the foo from an other TU. So the compiler needs to generate a relocation. but in this case it doesn't.

Maybe the problem is simply that foo is emitted with dso_local. Note that other backends(X86, aarch64) still generate relocations even with the dso_local.

llvmbot commented 5 days ago

@llvm/issue-subscribers-backend-arm

Author: None (Ralender)

Make file with the following named tmp.ll ```llvm define weak dso_local arm_aapcscc i32 @foo() { ret i32 9 } define dso_local arm_aapcscc ptr @get() { ret ptr @foo } ``` run: ```bash clang++ -target arm-none-linux-android tmp.ll -c -o out.o llvm-objdump -r out.o ``` the function pointer in `get` may get overridden by the `foo` from an other TU. so the compiler needs to generate a relocation. but in this case it doesn't.
llvmbot commented 5 days ago

@llvm/issue-subscribers-bug

Author: None (Ralender)

Make file with the following named tmp.ll ```llvm define weak dso_local arm_aapcscc i32 @foo() { ret i32 9 } define dso_local arm_aapcscc ptr @get() { ret ptr @foo } ``` run: ```bash clang++ -target arm-none-linux-android tmp.ll -c -o out.o llvm-objdump -r out.o ``` the function pointer in `get` may get overridden by the `foo` from an other TU. so the compiler needs to generate a relocation. but in this case it doesn't.