Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nvinson opened this issue Oct 11, 2022 · 1 comment · Fixed by #235
Closed

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

nvinson opened this issue Oct 11, 2022 · 1 comment · Fixed by #235

Comments

@nvinson
Copy link

nvinson commented Oct 11, 2022

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)
nvinson added a commit to nvinson/efivar that referenced this issue Oct 11, 2022
The current implementation attempts to use the linker to create aliases
for efi_well_known_guids and efi_well_known_names. It also tries to use
the linker to generate the variables efi_well_known_guids_end and
efi_well_known_names_end.

When building with clang, the generated linker result results in a
broken libefivar.so that causes programs to segfault when linked against
it.  This change does away with linker script hacker and instead
introduces pointers to store the locations of efi_well_known_guids_end
and efi_well_known_names_end.

Additionally, efi_well_known_guids and efi_well_known_names are now
created as pointers that point to the beginning of their respective
arrays.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
Fixes: rhboot#234
nvinson added a commit to nvinson/efivar that referenced this issue Oct 12, 2022
The current implementation attempts to use the linker to create aliases
for efi_well_known_guids and efi_well_known_names. It also tries to use
the linker to generate the variables efi_well_known_guids_end and
efi_well_known_names_end.

When building with clang, the generated linker result results in a
broken libefivar.so that causes programs to segfault when linked against
it.  This change does away with linker script hacker and instead
introduces pointers to store the locations of efi_well_known_guids_end
and efi_well_known_names_end.

Additionally, efi_well_known_guids and efi_well_known_names are now
created as pointers that point to the beginning of their respective
arrays.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
Fixes: rhboot#234
tpgxyz added a commit to OpenMandrivaAssociation/efivar that referenced this issue Oct 30, 2022
tpgxyz added a commit to OpenMandrivaAssociation/efivar that referenced this issue Oct 30, 2022
tpgxyz added a commit to OpenMandrivaAssociation/efivar that referenced this issue Oct 30, 2022
tpgxyz added a commit to OpenMandrivaAssociation/efivar that referenced this issue Oct 30, 2022
@tpgxyz
Copy link
Contributor

tpgxyz commented Nov 1, 2022

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

frozencemetery pushed a commit that referenced this issue Feb 6, 2023
The current implementation attempts to use the linker to create aliases
for efi_well_known_guids and efi_well_known_names. It also tries to use
the linker to generate the variables efi_well_known_guids_end and
efi_well_known_names_end.

When building with clang, the generated linker result results in a
broken libefivar.so that causes programs to segfault when linked against
it.  This change does away with linker script hacker and instead
introduces pointers to store the locations of efi_well_known_guids_end
and efi_well_known_names_end.

Additionally, efi_well_known_guids and efi_well_known_names are now
created as pointers that point to the beginning of their respective
arrays.

Signed-off-by: Nicholas Vinson <nvinson234@gmail.com>
Fixes: #234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants