The TI toolchain's armar command line is malformed when Ninja response files are used
I'm using the ARM TI toolchain version 18.1.6.LTS on Linux (Ubuntu 18).
The TI toolchain's armar
command accepts a response file, but only if it is the only argument given to the command. At the moment, the Module/Compiler/TI.cmake
file sets up the command line like so:
set(CMAKE_${lang}_ARCHIVE_CREATE "<CMAKE_AR> qr <TARGET> <OBJECTS>")
set(CMAKE_${lang}_ARCHIVE_APPEND "<CMAKE_AR> qa <TARGET> <OBJECTS>")
set(CMAKE_${lang}_ARCHIVE_FINISH "")
Only the first line above is interesting for this discussion. With Ninja, the <OBJECTS>
part can end up using a response file, which will result in a command line that looks like this:
path/to/armar qr libsomething.a CMakeFiles/targetname.rsp
This doesn't cause an error immediately, but libsomething.a
will end up containing the targetname.rsp
file as its only archive member instead of treating it as a response file. Anything that tries to use the libsomething.a
will (at best) fail to link with unresolved symbols, or (at worst) silently pick up symbols from somewhere else unexpectedly (could be disastrous!).
It has been a challenge constructing a working build for the TI toolchain with CMake 3.18+ due to breaking changes that have been progressively introduced since then. Part of the difficulty here is that CMake doesn't yet have a way to construct a valid armar
command line that uses a response file. I'm dealing with a build that fails without a response file due to the command line being too long. For the moment, I'm working around it by redirecting the command through a script that repairs the command line to something that works. I have to replace the command line set up by TI.cmake
with the following redirects:
set(CMAKE_${lang}_ARCHIVE_CREATE "${WRAPPED_CMAKE_AR} qr <TARGET> <OBJECTS>")
set(CMAKE_${lang}_ARCHIVE_APPEND "${WRAPPED_CMAKE_AR} qa <TARGET> <OBJECTS>")
WRAPPED_CMAKE_AR
points to my script, which looks for an argument that ends in .rsp
and writes a replacement response file that contains all preceding arguments plus the contents of that .rsp
file, then runs armar
with this modified response file. In a related problem, armar
requires a response file to be preceded with @
. CMake 3.21.0 sets CMAKE_${lang}_RESPONSE_FILE_LINK_FLAG
to a string containing a space to fix a questionable linker command line problem, so the wrapper script works around that problem too.
Some relevant issues/changes: