[compiler-rt] [Compiler-rt][test] Fix circular link dependency between builtins and libc (PR #199482)

Garvit Gupta via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 8 05:30:07 PDT 2026


quic-garvgupt wrote:

For the unresolved math symbol functions I have mentioned there is indeed only linear dependency and can be resolved by just chaning the linker order. However for other tests as shown below, there is cyclic dependency, which demonstrates cyclic dependency betrween librt and libc.

Walkthrough for a test to demonstrate why each order fails

  Order builtins.a -lc -lm:

  test introduces: { __addvdi3, printf }
     scan builtins.a
    +pull addvdi3.c.obj          -> introduces __compilerrt_abort_impl
    +pull int_util.c.obj         -> introduces  abort           --- unresolved
     scan libc.a (already past builtins.a)
    +pull printf.c.o             -> introduces  vfprintf, stdout
    +pull vfprintf.c.o           -> introduces  __aeabi_uldivmod --- unresolved
    +pull abort.c.o              -> resolves    abort
     scan libm.a
    (does not contain __aeabi_uldivmod)

  LINK FAILS: __aeabi_uldivmod is in builtins.a but builtins.a was already consumed.

  Order -lc -lm builtins.a:

  test introduces: { __addvdi3, printf }
     scan libc.a
    +pull printf.c.o             -> introduces  vfprintf
    +pull vfprintf.c.o           -> introduces  __aeabi_uldivmod --- unresolved
     scan libm.a
    (does not contain __aeabi_uldivmod or __addvdi3)
    scan builtins.a (libc already past)
    +pull addvdi3.c.obj          -> resolves __addvdi3 (resolved); introduces __compilerrt_abort_impl
    +pull aeabi_uldivmod.S.obj   -> resolves __aeabi_uldivmod (resolved)
    +pull int_util.c.obj         -> resolves __compilerrt_abort_impl (resolved); introduces abort  --- unresolved
  unresolved

  LINK FAILS: abort is in libc.a but libc.a was already consumed.

The unresolved symbols (__aeabi_uldivmod, abort) do not originate from the test code. They are pulled in buildins and libc respectively. Each archive introduces an undefined reference that only the other archive can resolve therefore a linear scan is not sufficient would need to wrap librt and libc under `start-group/end-group`.

https://github.com/llvm/llvm-project/pull/199482


More information about the llvm-commits mailing list