How do I add a lib library path to a subpart of LLVM?

Question

I tried compiling llvm15 on Ubuntu with AArch64 architecture. However, I encountered the following problems:

1. /usr/bin/ld: cannot find -lgcc_s, some of the errors are as follows:

[build] [73/4456   0% :: 1.026] Linking CXX static library lib/clang/15.0.1/lib/aarch64-unknown-linux-gnu/libclang_rt.fuzzer_no_main.a
[build] FAILED: lib/clang/15.0.1/lib/aarch64-unknown-linux-gnu/libclang_rt.fuzzer_no_main.a 
[build] : && /usr/bin/cmake -E remove lib/clang/15.0.1/lib/aarch64-unknown-linux- ........
[build] /usr/bin/ld: cannot find -lgcc_s
[build] /usr/bin/ld: cannot find -lgcc_s
[build] clang: error: linker command failed with exit code 1 (use -v to see invocation)
[build] [73/4456   0% :: 1.261] Linking CXX shared library lib/clang/15.0.1/lib/aarch64-unknown-linux-gnu/libclang_rt.asan.so
[build] [73/4456   0% :: 1.322] Linking CXX static library lib/clang/15.0.1/lib/aarch64-unknown-linux-gnu/libclang_rt.fuzzer_interceptors.a
[build] FAILED: lib/clang/15.0.1/lib/aarch64-unknown-linux-gnu/libclang_rt.fuzzer_interceptors.a 
[build] : && /usr/bin/cmake -E remove lib/clang/15.0.1/lib/aarch64-unknown-linux-gnu/libclang_rt.fuzzer_interceptors.a && /usr/bin/ar Dqc lib/clang/15.0.1/lib/
......

2. Modify the CMakeLists .txt

I tried adding something like the following to the CMakeLists .txt llvm, but configure didn’t work.

link_directories("/usr/lib/gcc/aarch64-linux-gnu/9/" "/usr/lib/aarch64-linux-gnu/")

link_libraries("/usr/lib/gcc/aarch64-linux-gnu/9/libgcc_s.so")

The same problem in 1 will appear.

Maybe there is a problem with what I added, and the specific subproject is configured like this. I took a screenshot below.

add_compiler_rt_object_libraries(RTfuzzer_interceptors
  OS ${FUZZER_SUPPORTED_OS}
  ARCHS ${FUZZER_SUPPORTED_ARCH}
  SOURCES FuzzerInterceptors.cpp
  CFLAGS ${LIBFUZZER_CFLAGS}
  DEPS ${LIBFUZZER_DEPS})

# Tries to add an "object library" target for a given list of OSs and/or
# architectures with name "<name>.<arch>" for non-Darwin platforms if
# architecture can be targeted, and "<name>.<os>" for Darwin platforms.
# add_compiler_rt_object_libraries(<name>
#                                  OS <os names>
#                                  ARCHS <architectures>
#                                  SOURCES <source files>
#                                  CFLAGS <compile flags>
#                                  DEFS <compile definitions>
#                                  DEPS <dependencies>
#                                  ADDITIONAL_HEADERS <header files>)
function(add_compiler_rt_object_libraries name)
  cmake_parse_arguments(LIB "" "" "OS;ARCHS;SOURCES;CFLAGS;DEFS;DEPS;ADDITIONAL_HEADERS"
    ${ARGN})
  set(libnames)
  if(APPLE)
    foreach(os ${LIB_OS})
      set(libname "${name}.${os}")
      set(libnames ${libnames} ${libname})
      set(extra_cflags_${libname} ${DARWIN_${os}_CFLAGS})
      list_intersect(LIB_ARCHS_${libname} DARWIN_${os}_ARCHS LIB_ARCHS)
    endforeach()
  else()
    foreach(arch ${LIB_ARCHS})
      set(libname "${name}.${arch}")
      set(libnames ${libnames} ${libname})
      set(extra_cflags_${libname} ${TARGET_${arch}_CFLAGS})
      if(NOT CAN_TARGET_${arch})
        message(FATAL_ERROR "Architecture ${arch} can't be targeted")
        return()
      endif()
    endforeach()
  endif()

  # Add headers to LIB_SOURCES for IDEs
  compiler_rt_process_sources(LIB_SOURCES
    ${LIB_SOURCES}
    ADDITIONAL_HEADERS
      ${LIB_ADDITIONAL_HEADERS}
  )

  foreach(libname ${libnames})
    add_library(${libname} OBJECT ${LIB_SOURCES})
    if(LIB_DEPS)
      add_dependencies(${libname} ${LIB_DEPS})
    endif()

    # Strip out -msse3 if this isn't macOS.
    set(target_flags ${LIB_CFLAGS})
    if(APPLE AND NOT "${libname}" MATCHES ".*\.osx.*")
      list(REMOVE_ITEM target_flags "-msse3")
    endif()

    # Build the macOS sanitizers with Mac Catalyst support.
    if (APPLE AND
        "${COMPILER_RT_ENABLE_MACCATALYST}" AND
        "${libname}" MATCHES ".*\.osx.*")
      foreach(arch ${LIB_ARCHS_${libname}})
        list(APPEND target_flags
          "SHELL:-target ${arch}-apple-macos${DARWIN_osx_MIN_VER} -darwin-target-variant ${arch}-apple-ios13.1-macabi")
      endforeach()
    endif()

    set_target_compile_flags(${libname}
      ${extra_cflags_${libname}} ${target_flags})
    set_property(TARGET ${libname} APPEND PROPERTY
      COMPILE_DEFINITIONS ${LIB_DEFS})
    set_target_properties(${libname} PROPERTIES FOLDER "Compiler-RT Libraries")
    if(APPLE)
      set_target_properties(${libname} PROPERTIES
        OSX_ARCHITECTURES "${LIB_ARCHS_${libname}}")
    endif()
  endforeach()
endfunction()

3. Modify LD configuration - no permission

After a Google search, I found that I can modify the configuration file of LD, but the user I use does not have permission to modify the changed file and cannot execute sudo.

$ cat /etc/ld.so.conf.d/aarch64-linux-gnu.conf 
# Multiarch support
/usr/local/lib/aarch64-linux-gnu
/lib/aarch64-linux-gnu
/usr/lib/aarch64-linux-gnu

4. Modify the environment variables for the current user

I tried to add libgcc_s directory where .so is located to my current user’s LD_LIBRARY_PATH, and I still got an error in 1 when compiling.

I need help!

Is there any other way to enable the ld linker to find ‘libgcc_s.so’ when I can’t use sudo, yes, when compiling llvm via cmake? Or do I have a problem with the above workaround?

This seems like a question better suited for LLVM directly to me.