[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)

Paul Osmialowski via cfe-commits cfe-commits at lists.llvm.org
Sun Dec 1 07:06:16 PST 2024


pawosm-arm wrote:

> @pawosm-arm See also https://wiki.gentoo.org/wiki/Project:Quality_Assurance/As-needed#Importance_of_linking_order. It is common for distributions to enable `-Wl,--as-needed` via patches to the compiler or configuration files.

Indeed, the distributions couldn't avoid this annoying behavior of clang (spitting `undefined reference to `main'`) when started without any command line params:

```
$ clang
/usr/bin/x86_64-pc-linux-gnu-ld.bfd: /usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/Scrt1.o: in function `_start':
(.text+0x17): undefined reference to `main'
clang: error: linker command failed with exit code 1 (use -v to see invocation)

$ clang --no-default-config
clang: error: no input files

$ clang -###
clang version 18.1.8
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/18/bin
Configuration file: /etc/clang/x86_64-pc-linux-gnu-clang.cfg
 "/usr/bin/x86_64-pc-linux-gnu-ld.bfd" "--hash-style=gnu" "--eh-frame-hdr" "-m" "elf_x86_64" "-pie" "-dynamic-linker" "/lib64/ld-linux-x86-64.so.2" "-o" "a.out" "/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/Scrt1.o" "/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crti.o" "/usr/lib/gcc/x86_64-pc-linux-gnu/14/crtbeginS.o" "-L/usr/lib/gcc/x86_64-pc-linux-gnu/14" "-L/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64" "-L/lib/../lib64" "-L/usr/lib/../lib64" "-L/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../x86_64-pc-linux-gnu/lib" "-L/lib" "-L/usr/lib" "-z" "relro" "-z" "now" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "-lc" "-lgcc" "--as-needed" "-lgcc_s" "--no-as-needed" "/usr/lib/gcc/x86_64-pc-linux-gnu/14/crtendS.o" "/usr/lib/gcc/x86_64-pc-linux-gnu/14/../../../../lib64/crtn.o"

$ cat /etc/clang/x86_64-pc-linux-gnu-clang.cfg
# This configuration file is used by x86_64-pc-linux-gnu-clang driver.
@gentoo-common.cfg
@gentoo-common-ld.cfg
@gentoo-cet.cfg`
```


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


More information about the cfe-commits mailing list