--trace-symbol=<symbol> only traces one symbol at a time, add :
- --trace-all-symbols to trace all symbols
- --trace-symbols-from-file=<file> to trace symbols referenced or defined in a file
Differential D96613
[lld] Add options to trace all symbols and to trace all symbols originated from a file hoy on Feb 12 2021, 9:11 AM. Authored by
Details
Diff Detail
Event TimelineComment Actions I created https://sourceware.org/bugzilla/show_bug.cgi?id=27407 asking for binutils opinions.
Comment Actions Thanks for gather's inputs from binutils. I'm curious about how they view this. Regarding the throughput impact, I was seeing --trace-all-symbols slowed down the linker by 2x for a final executable around 60M unfortunately. Since it is a debug switch, I would imagine people whoever use this would be willing to pay for its cost. Comment Actions I even pinged that for you: https://sourceware.org/pipermail/binutils/2021-February/115455.html
Comment Actions Thanks for pinging for me!
Comment Actions https://sourceware.org/bugzilla/show_bug.cgi?id=27407 % ld.lld @response.txt $(llvm-nm -Du usr/lib64/libc.so.6 | awk '{print "-y"substr($0,20)}') This even works with versioned symbols while the patch doesn't. You can tweak -u: e.g. -U dumps defined symbols (-U is not in nm). The patch uses this->file, however, the value may change if the symbol gets resolved to other files. In the cases I can conceive we want the trace of the full lifetime of a symbol, not only when it is bound to a specific file. Comment Actions In general, while there's a lot of value in being able to compose tools, I strongly disagree that it's an adequate replacement for having functionality directly built into a tool:
Comment Actions My opinion on this is still case by case. For the particular features, (1) the lack of customization of -u/-U` and (2) the this->file usage is my main concern about the new option.
New options have education costs. I've heard many internal reports where they want some build analysis features but they don't investigate(know) --cref/-Map/-y/etc.
I think a small set of composable options for build dependency analysis will be useful, but we need to consolidate the requests and think of their composability/maintenance/etc. Apologies but I feel that "Linux utilities have different arguments or behaviors than their BSD" in this particular context is probably a weak argument: here we use LLVM binary utilities and a common 'awk' (which can be reimplemented in build system language straightforwardly). Many downstream groups have bundled LLVM binary utilities as platform-neutral utilities which are already used heavily in build systems. We don't necessarily re-invent features provided by them in LLD. Comment Actions Yup, we should still be evaluating new options on their merits and drawbacks, of course. I just meant that we shouldn't be preventing some functionality from being built directly into a tool just because you can also emulate the same results by composing other tools.
Agreed, but I also think they're more discoverable (e.g. by reading the --help output or man pages).
Comment Actions I edited my previous comment to include a bit more information. For discoverability, if people know that --trace-symbol, re-inventing this mechanism is simple. nm (llvm-nm) is well-known utility to dump the symbol table. Composing nm and ld.lld together is straightforward. Comment Actions I agree that we should be thinking about the composability and maintenance burden of new options, and thinking about this in a holistic way (and not just always adding one-off options for each request). At the same time, I disagree with your assessment of how straightforward it is to compose different tools together. Fair point about the awk functionality in your command being the same across Unixes, but awk still isn't a thing on Windows, and whether it's straightforward or not to reimplement the equivalent functionality in your build system language depends on your build system. Furthermore, I think text processing is inherently fragile in general; it's fair to assume that a tool like llvm-nm isn't going to be changing its output format, but you still have to put a lot more thought into setting up an appropriate pipeline than you would into using a built-in option. Case in point: you're using the following invocation: llvm-nm -Du /usr/lib64/libc.so.6 | awk '{print "-y"substr($0,20)}' I don't know why this is, but both GNU nm and llvm-nm print a different number of leading spaces for 32 vs. 64-bit binaries. If I do llvm-nm -Du /usr/lib/libc.so.6 (instead of /usr/lib64/libc.so.6), I need to change the substr amount to 12 instead of 20. I could use $2 (as in the second field) instead, but that'll break if my symbol name has spaces in it (which definitely occurs for Objective-C, at least). (Incidentally, you're not putting quotes around your -y command, so it'll also break if the symbol name has spaces in it, which is one of the generally fragile things about shell pipelines.) Fortunately, llvm-nm has a --just-symbol-name option (which at least my version of GNU nm doesn't), which'll work regardless of the output format for the particular architecture, and handle symbol names with spaces without any issues. There's clear value to having the --just-symbol-name flag IMO, even though you could theoretically emulate the same functionality with a shell pipeline, since it lets you not have to worry about all these caveats. Comment Actions @MaskRay I think your concern is primarily about the extra condition checks in Symbol::needToTraceSymbol that may slow down the linker. Is there a linker performance testing system on your side that you can help evaluate it? I have manually run the patch against medium-sized programs and haven't seen regressions. Otherwise, I agree with @smeenai that we should be open to changes that make life easier with little cost. Comment Actions I have several concerns.
https://sourceware.org/bugzilla/show_bug.cgi?id=27407 If you can make arguments there, it will probably make this proposal more competitive. Comment Actions Our internal projects mostly use thinLTO thus the overhead here is negligible. Without thinLTO, generated code becomes much smaller (due to lack of cross-module inlining). Anyway, I'll continue my measurement. If there's any regression, I think we can optimize the checks to just favor non-debug scenario, like another bool flag to identify if config->traceSymbolsFromFile is empty?
Does the exiting --trace-symbol handle versioned symbols?
Is this for weak symbols? --trace-symbols-from-file aims to trace where a definition of a symbol is finally picked up.
As @smeenai pointed out, that approach also has limitations.
Sorry, I don't quite get this. Are we trying to have the gnu linker implement the two switches as well? I don't see an objection on their side. Comment Actions Yes. See verneed-shared.s
Not just weak symbols. See resolveUndefined where an undefined symbol's file can be replaced.
You are proposing new options, so you need to justify the options. I've also asked other folks and many feel that this is unnecessary.
When things are in doubts, one tie-breaking thing you can try is to make other implementations accept your proposal. That could justify the merit of the proposal. |
clang-tidy: warning: invalid case style for parameter 'Args' [readability-identifier-naming]
not useful