[PATCH] D97448: ELF: Create unique SHF_GNU_RETAIN sections for llvm.used global objects

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 8 21:20:19 PDT 2021


MaskRay added a comment.

In D97448#2933400 <https://reviews.llvm.org/D97448#2933400>, @nikic wrote:

> Just FYI this patch exposes a bug in at least `GNU gold (GNU Binutils for Ubuntu 2.34) 1.16` when used in conjunction with `section(".init_array")`.
>
>   ; RUN: clang -fuse-ld=gold %s
>   #include <stdio.h>
>   static void do_init(void) { printf("Foobar\n"); }
>   
>   __attribute__((used, retain, section(".init_array")))
>   static void (*init)(void) = &do_init;
>   
>   int main() { return 0; }
>
> The symbol is not placed between `__init_array_start`/`__init_array_end` and thus the init function is not run.

The gold bug is fixed in 2.36 (https://sourceware.org/bugzilla/show_bug.cgi?id=27039)

> Following your recommendation, we switched the `#[used]` attribute in rust to use `llvm.compiler.used` instead of `llvm.used`. Hopefully that won't have other fallout.

I informed Rust folks in March. https://github.com/rust-lang/rust/issues/40289#issuecomment-788567604
Switching to `llvm.compiler.used` improves compatibility with GCC/Clang.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D97448/new/

https://reviews.llvm.org/D97448



More information about the llvm-commits mailing list