This is an archive of the discontinued LLVM Phabricator instance.

[CMake] Allow passing extra options to extract_symbols.py.
ClosedPublic

Authored by simon_tatham on Nov 10 2021, 3:41 AM.

Details

Summary

When cross-compiling LLVM in an environment where there is an
objdump binary available but it does not understand the target
platform's object file format, extract_symbols.py fails, because its
initial check for tool availability decides that the existence of
objdump at all is good enough to settle on it as the tool of choice.

In such an environment it's useful to work around this by telling
extract_symbols.py to use llvm-readobj instead. The script itself has
an option for that, but its invocation in AddLLVM.cmake wasn't
providing a mechanism to add extra options passed through for the
cmake command line.

Diff Detail

Event Timeline

simon_tatham created this revision.Nov 10 2021, 3:41 AM
simon_tatham requested review of this revision.Nov 10 2021, 3:41 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 10 2021, 3:41 AM
DavidSpickett added a subscriber: DavidSpickett.

Given that the only flag not specified already is --tools would it make more sense to have LLVM_EXTRACT_SYMBOLS_TOOLS?

My own answer to that is "sods law some other flag is added later and we need another cmake var". So you could at least put the extra flags on the end of the COMMAND. Then even though the one flag you'll usually want is --tools you could override the mangling or export location if you wanted to.
(plus extra flags winning over the defaults makes more sense in general)

I'm not sure it really makes sense to be able to override the output file location in the context of a build system – surely if you want to do that, you also have to tell cmake to change the OUTPUT parameter of the custom command, or the build products won't end up where the next build step expects them! Perhaps I should move this to after --mangling, though.

I agree about FLAGS being more futureproof than TOOLS. (Plus, if you have a TOOLS definition then you have to do some extra cmake messing about to decide whether to add a --tools option at all, in the likely case that you just wanted the default).

DavidSpickett added a comment.EditedNov 15 2021, 3:30 AM

(further to some internal discussion about argparse having issues when you place these extra flags in certain positions)

What you could do is keep it as it is and update the help text of the variable to note that it will not override anything already chosen by the build system. Seems fair since like you said you'd have to make other cmake changes to account for that if it did.

So it's more "extra flags" than flags. (but the name is fine as is)

Improved the help text for the new variable.

Summarising what I said about argparse internally:

The --tools option to extract_symbols.py is defined using nargs="*", which means that you can write multiple argv words after it that will all be treated as operands, e.g. --tools nm objdump. In fact, argparse will carry on consuming words from argv until it sees another one that looks like an option.

So if I moved ${LLVM_EXTRACT_SYMBOLS_FLAGS} in this patch to after the --mangling option, the effect would be that if you ran

cmake -DLLVM_EXTRACT_SYMBOLS_FLAGS="--tools nm objdump"

then the generated command line would look like

extract_symbols.py --mangling=whatever --tools nm objdump libfoo.a libbar.a -o output-file

and argparse would try to treat libfoo.a as an extra argument to --tools, and complain that it isn't a legal one!

DavidSpickett accepted this revision.Nov 15 2021, 5:59 AM
This revision is now accepted and ready to land.Nov 15 2021, 5:59 AM