Skip to content

sel4test: Handle retain attr issue in build args#102

Draft
kent-mcleod wants to merge 1 commit intoseL4:masterfrom
kent-mcleod:kent/retain
Draft

sel4test: Handle retain attr issue in build args#102
kent-mcleod wants to merge 1 commit intoseL4:masterfrom
kent-mcleod:kent/retain

Conversation

@kent-mcleod
Copy link
Member

It seems that detecting support for the right keywords used to instruct the linker to retain symbols is pretty unstable. Alternative approach is to move conditional check into the build script and pick behavior based on the toolchains selected.

An approach to address #97

It seems that detecting support for the right keywords used to instruct
the linker to retain symbols is pretty unstable. Alternative approach
is to move conditional check into the build script and pick behavior
based on the toolchains selected.

Signed-off-by: Kent McLeod <[email protected]>
@Ivan-Velickovic
Copy link

With GCC this gets rid of the errors for retain, I now run into seL4/sel4test#137.

With LLVM (../init-build.sh -DPLATFORM=qemu-arm-virt -DTRIPLE=aarch64-none-elf) I get:

ld.lld: error: unable to find library -lgcc
ld.lld: warning: apps/sel4test-driver/musllibc/build-temp/stage/lib/libc.a: archive member '/' is neither ET_REL nor LLVM bitcode
ld.lld: warning: apps/sel4test-driver/musllibc/build-temp/stage/lib/libc.a: archive member '//' is neither ET_REL nor LLVM bitcode
clang++: error: ld.lld command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.

@Indanz
Copy link
Contributor

Indanz commented May 23, 2025

Adding "-fno-lto" should fix Ivan's Clang warning. I think we should disable link time optimisation by default for both clan and gcc.

Edit: Created PR #103 that limits retain for Clang at compile time, keeping the existing has attribute check.

Comment on lines -99 to -104
#if defined(__has_attribute) && __has_attribute(retain)
#define ATTR_USED_RETAIN __attribute__((used,retain))
#else
#define ATTR_USED_RETAIN __attribute__((used))
#endif

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still want to keep this check though, so instead of a Cmake check, can't we add defined(__clang__) here?

list(SORT deps)

add_library(sel4test STATIC EXCLUDE_FROM_ALL ${deps})
if(CMAKE_C_COMPILER_ID STREQUAL "Clang")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if you compile with GCC but link with ld.lld or compile with Clang but link with ld.bfd?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we have to worry about anyone compiling with gcc and linking with ld.lld. Clang has better checks for has-retain attribute checks, unlike the buggy gcc one which says it's fine and then complains. So supposedly Clang with ld.bdf should be fine.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair enough. It's usually the case though that Clang will fall back to ld.bfd (and using GCC's libgcc.a etc) even implicitly if it is not told explicitly to use ld.lld. This has been the case for seL4 building with LLVM/Clang before I pushed support for ld.lld.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, but does Clang support GCC's link-time optimisation format? I don't expect it does, in which case it shouldn't do link-time optimisation when using ld.bdf.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion, but just for completeness:

Clang supports two types of link time optimization:

  • Full LTO, which is the traditional approach also used by GCC where the whole link unit is analyzed at once. Using it is no longer recommended.
  • ThinLTO, where the link unit is scanned and split up into multiple parts.

@heshamelmatary
Copy link
Contributor

With GCC this gets rid of the errors for retain, I now run into seL4/sel4test#137.

With LLVM (../init-build.sh -DPLATFORM=qemu-arm-virt -DTRIPLE=aarch64-none-elf) I get:

ld.lld: error: unable to find library -lgcc

If you're using LLVM/Clang to build, and unlike GCC/ld.bfd, you'll need to manually tell your linker (ld.lld) where to find -lgcc (or ideally compiler_rt). You can do this by passing the GCC's libgcc.a directory e.g., -DCMAKE_EXE_LINKER_FLAGS="-Wl,-L$GCC_LIB_PATH when you're configuring sel4test

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 this pull request may close these issues.

4 participants