Analysis-based toolchain tools/job actions without output

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Analysis-based toolchain tools/job actions without output

shirley breuer via cfe-dev
Greetings everyone,

I'm using a slightly modified version of Clang and LLVM to build
binaries that are effectively firmware for custom hardware -- code
that gets compiled down to flat executable code which will be dropped
into some flash memory on a device at a known, fixed address. These
files exit the compilation process from LLD as ELF executables before
being validated and converted to binary blobs via objcopy. The
validation process takes place using a custom tool, and all it does is
check to make sure all the final ELF sections are read-only. (There
are probably better ways of doing this, but that's certainly outside
of the scope of this email!)

The validation and extraction processes are accomplished using
individual build steps in a terrible custom build system (in the name
of OS compatibility despite the fact that we only use this on a single
platform) which can't be replaced any time soon. There is a TON of
code involved in these build steps using this horrible internal build
system and its continued use is equivalent to indentured servitude for
technical debt. However, we're stuck with it for the foreseeable

In an effort to make this easier and to reduce the amount of garbage
code my team has to deal with in this mockery of a build system, I
would like to convert the ELF validation process into a custom job
action to Clang's compilation pipeline -- specifically, actions
defined by `clang::Driver::BuildActions()`
I've done this before for tools such as `llvm-link` to provide
automatic bitcode linking, but that tool produces output which can be
fed back into the compilation pipeline for further actions such as
code generation.

The ELF validation tool produces no output -- it simply checks the
executable and exits with a 0 status if it determines everything is
good, or it prints relevant error messages and exits with a 1 status.
This is where I run into problems. In my attempts to make this tool a
step in Clang's compilation process, I've not found a way to tell
Clang to simply use the output from the preceding step/job action as
the output for this tool. As a bandage fix, I've modified the
validator tool to accept a `-o=<XYZ>` argument and to use that to
create a symlink of the input file. I can then feed that symlink back
to Clang. Clang is happy with this, but it's *not* a good solution.

I see other job actions that don't produce output (such as those for
handling `-fsyntax-only` and `-verify-pch`, but those also act as
terminators for the compilation process.

Is there a way to do what I'm trying to do within Clang without
halting the pipeline?

Jonathan Smith (jvstech)
cfe-dev mailing list
[hidden email]