[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 08:00:09 PST 2024


pawosm-arm wrote:

> > I took a look and I think it may be too awkward to do, as we'd want to run e.g. readelf afterwards. But an example is `lld/test/ELF/as-needed-not-in-regular.s`. The idea being: if `-Wl,--as-needed` is in the config file, do we correctly prune an unnecessary library from a built object, or is the order wrong? We can check that with `llvm-readelf`.
> 
> There are two problems here. First, following the readelf path goes too far into the linker competences, whatever is set for the linker, the linker is obliged to do, and the order of whatever is set for the linker is already tested by other `-Wl,` occurrences in the currently available test cases.
> 
> Yet your request also exposes another problem, and I can see that further comments also mention it. With my patch, there is no way to affect the user's command line linker input parameters. So if a config file is a mean for turning clang's behavior into the gcc's behavior (AFAIR, gcc always emits `-Wl,--as-needed` at the beginning of the linker invocation command line, while clang doesn't do that), this patch rejects such possibility. Something more clever is needed, the positional idea seems the right one, I could see it like this (a config file example, notice the pipe `|` character):
> 
> ```
> -Wall -Wl,--as-needed | -lm -Wl,-Bstatic -lhappy -Wl,-Bdynamic
> ```
> 
> ...things after the pipe would be appended at the end of the parameters list and only when it is known that there will be the linking. But this would require a modification in the config file reading routine, the second list of config options would have to be created much earlier than my patch proposes.
> 
> Back to the drawing board then.

Actually, it was easy to implement, I've presented it here.


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


More information about the cfe-commits mailing list