[PATCH] D54489: Implement -frecord-command-line (-frecord-gcc-switches)

Scott Linder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 15 06:36:43 PST 2018


scott.linder added inline comments.


================
Comment at: docs/ClangCommandLineReference.rst:797
+
+Generate a section .LLVM.command.line containing the clang driver command line.
+
----------------
rjmccall wrote:
> 1. Is this section always called `.LLVM.command.line`, or does it differ by target object-file format?
> 2. For that matter, is this actually supported by all object-file formats?
> 3. Please describe the format of the section.  Is it just a flat C string?  Is it nul-terminated?  Are different options combined with spaces, and if so, does that mean that interior spaces in command line arguments are impossible to distinguish?  If the latter, I assume that this is required behavior for backward compatibility; please at least apologize for that in the documentation. :)
For (1) I think the answer should be that we emit `.LLVM.command.line` (or whatever name we land on) for every object-file format with the concept of names for sections.

For (2), I have only implemented this for ELF so far in LLVM. I don't know how reasonable that is, and if it isn't I can look at adding it to other common object-file formats that LLVM supports.

For (3), my current proposal for the format is the same as the `.comment` section for idents: null-surrounded strings. Interior spaces are escaped, in the same manner as for the -g variant. There may still be more thought to put into the format, as the GCC version null-terminates each individual option; the reason I avoided this is that during object linking the options of many command-lines simply get mixed together, which seems less than useful.

As an example, for ELF `clang -frecord-command-line -S "foo .c"` produces the ASM:

```
.section        .LLVM.command.line,"MS", at progbits,1
.zero   1
.ascii  "/usr/local/bin/clang-8 -frecord-command-line -S foo\\ .c"
.zero   1
```

And for multiple command-lines in a single object (e.g. linking three objects with recorded command-lines) this would be:

```
.section        .LLVM.command.line,"MS", at progbits,1
.zero   1
.ascii  "/usr/local/bin/clang-8 -frecord-command-line -c foo\\ .c"
.zero   1
.ascii  "/usr/local/bin/clang-8 -frecord-command-line -some -unique -options -c bar.c"
.zero   1
.ascii  "/usr/local/bin/clang-8 -frecord-command-line -something -else -c baz.c"
.zero   1
```

I will try to capture more of this in the documentation.


https://reviews.llvm.org/D54489





More information about the cfe-commits mailing list