rhboot / efivar

Tools and libraries to work with EFI variables
GNU Lesser General Public License v2.1
238 stars 104 forks source link

Invalid libefivar.so generated when building with clang-15. #234

Closed nvinson closed 1 year ago

nvinson commented 1 year ago

description

When building with clang-15, the generated libefivar.so library is broken. The broken library causes applications to link to it to segfault on start.

steps to reproduce

  1. run CFLAGS="-march=native -O2 -pipe -ggdb" CXXFLAGS="-march=native -O2 -pipe -ggdb" CC=clang LD=ld.lld LDFLAGS="-Wl,-O1 -Wl,--as-needed -fuse-ld=lld -rtlib=compiler-rt -unwindlib=libunwind" make
  2. write test.c
  3. run clang -Wl,-rpath,$PWD/src -Lsrc/ test.c -o test -lefivar
  4. run test

Expected results

the test binary returns the libefivar version number.

Actual results

the test binary segfaults.

Additional notes

test.c:
#include<stdio.h>
#include<efivar/efivar.h>

int main()
{
  printf("%d\n", efi_get_libefivar_version());
  return 0;
}
clang -v
clang version 15.0.2
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/15/bin
Configuration file: /etc/clang/clang.cfg
System configuration file directory: /etc/clang
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
ld.lld -v
LLD 15.0.2 (compatible with GNU linkers)
tpgxyz commented 1 year ago

Hi, just to confirm that with this PR i'm able to compile efivar with LLVM/clang-15.0.3. One thing i did not verified is does efivar without that PR is the culprit of segfault of sytemd-boot on my aarch64. Will drop a line here after upate to systemd-252 with efivar+PR234