<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/67209>67209</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Linker options in Clang config files break `clang` invocation
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
thesamesam
</td>
</tr>
</table>
<pre>
Setting certain linker options like `-Wl,-z,now` or `-Wl,-z,lazy` in `/etc/clang/clang.cfg` breaks `clang` and `clang -v`, giving both noise in the output as well as affecting its exit code.
This is unexpected, especially given this is the way distros have been recommended to set default flags.
(It also tries to create an `a.out`.)
```console
$ cat /tmp/test
-Wl,-z,now
$ clang --no-default-config -v ; echo $?
clang version 17.0.1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/17/bin
System configuration file directory: /etc/clang
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/13
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
0
$ clang --no-default-config --config /tmp/foo -v ; echo $?
clang version 17.0.1
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm/17/bin
Configuration file: /tmp/foo
System configuration file directory: /etc/clang
Selected GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/13
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
"/usr/lib/llvm/17/bin/x86_64-pc-linux-gnu-ld" -pie --hash-style=gnu --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../lib64/Scrt1.o /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../lib64/crti.o /usr/lib/gcc/x86_64-pc-linux-gnu/13/crtbeginS.o -L/usr/lib/gcc/x86_64-pc-linux-gnu/13 -L/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../x86_64-pc-linux-gnu/lib -L/lib -L/usr/lib -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/13/crtendS.o /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../lib64/crtn.o
x86_64-pc-linux-gnu-ld: error: undefined symbol: main
>>> referenced by /usr/lib/gcc/x86_64-pc-linux-gnu/13/../../../../lib64/Scrt1.o:(_start)
clang: error: linker command failed with exit code 1 (use -v to see invocation)
1
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVk1v4zYQ_TX0ZUBBJmU5PviQOFWxwN5SoMeAIkcSG4o0SMqx8-sLSnI-vGnaBNtDgQIKFZMz7w1nqOETIejWIm7J6oasbhdiiJ3z29hhEH36W9ROnbZ3GKO2LUj0UWgLRtsH9OD2UTsbwOgHBFLm9HdD2I4-Ebaz7pGUOTh_MW_E0yktaJsWCKswSsIqaYRtz-9MNm2yqT2Kh5DspuUyB2HV82-ghxFiB60-pOhqFzuwTgdM8LFDcEPcDxFEgEc0Jr1F06Ac96JjADzqCNIpzEh-S_Lrafyt0wF0gMHicY8yokokGPYotTDmlPgwEUxmiehRnEDpEL0L0IkDQo1owaN0fY9WoYLoIGAEhY0YTITGiDa8YSXs6lsEYYKD6DWG5CE9ioggxmSJzA2RlHlG2OaNY5lPj3Q2OINnuAKkiEBYFft9GjHEaemiTG9iKGDOLbWOzsFS6WyjU76B8BtA2TkgrCC8mrwmjwP6oJ2F5TrLs-WcSeFbjIRfw_GqvC8LupfUaDscaWuHc7I9CgW9U2iS4d4FfZyWvtkQhTGobrVPS4RVQ_CEVUbXaTSHnrBquSasqrWdfO5OIWIPU8SDF-mAQqMNgtIeZXT-NEO9PniTK5qx2PDrbgd64h793-FuZXJ-b1OsWvI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