mstorsjo / llvm-mingw

An LLVM/Clang/LLD based mingw-w64 toolchain
Other
1.75k stars 176 forks source link

Treat file content as command line (feature request) #407

Closed top-master closed 4 months ago

top-master commented 4 months ago

MingW supports listing .o files in an external file, instead of passing as command-line. I would like this to be supported by llvm-mingw as well.

Example

For example, consider object_script.Qt5Core.Release file's content to be:

INPUT(
./release/qstring.o
./release/qstringbuilder.o
./release/qstringlist.o
./release/qstringlistmodel.o
./release/qstring_compat.o
);

Then the MingW's command-line can be as short as:

g++ $(LFLAGS) -o $(TARGET) object_script.Qt5Cored.Release  $(LIBS)

Where:

LFLAGS = -shared -Wl,-subsystem,windows -Wl,--out-implib,D:/projects/qt5/qtbase/lib/libQt5Cored.a
LIBS = -lole32 -luuid -lws2_32 -ladvapi32
TARGET = D:/projects/qt5/qtbase/lib/Qt5Cored.dll

However, llvm-mingw gives error:

ld.lld: error: object_script.Qt5Core.Release: unknown file type
clang-17: error: linker command failed with exit code 1
mstorsjo commented 4 months ago

This is an issue about what LLD supports and does not support, in mingw mode.

LLD does support taking a list of command arguments, in a file, when using the "response file" syntax, where you just list the command line arguments in a file, and pass this file to the linker as @filename.

Your example, which uses the extra syntax INPUT(...), and passing it as a regular file, is treating this file as linker script. Linker script is a very large feature, complex and messy to implement, even if the INPUT(...) case looks quite trivial.

The issue here is that some build tools, like qmake in your case, and libtool in some other cases, seem to prefer to use linker script to achieve this, rather than using response files.

In the case of qmake, this was fixed in 2018 in https://github.com/qt/qtbase/commit/d92c25b1b4ac0423a824715a08b2db2def4b6e25, to make qmake prefer response files over linker script. This fix is part of qtbase v5.12.0 and later.

top-master commented 4 months ago

They could at least support INPUT( syntax, and leave other parts, but in my case, I will simply add support for "response file" syntax.

Hence I checked how response file works, basically the command-line needs an additional @ sign:

g++ $(LFLAGS) -o $(TARGET) @object_script.Qt5Cored.Release  $(LIBS)

Then the importan part, the syntax of the response file: