[PATCH] D46628: [ELF] Add --strip-debug-non-line option

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 24 06:08:43 PDT 2019


MaskRay added a comment.

In D46628#1555375 <https://reviews.llvm.org/D46628#1555375>, @luciang wrote:

> > So the benefit is a smaller output size.
>
> Yes. That's what we're currently using gold + strip-debug-non-line for: to reduce binary sizes in a context where a very large number of very large binaries are produced and executed.
>
> We've also considered the items you brought up (building and deploying a separate tool to strip out the debug info after creation, create .o with minimal set of debug info), but went with this approach for:
>
> - lld feature parity with gold
>   - based on initial response to earlier version of the diff it seemed desirable
>   - the flag is useful on its own
> - producting large binaries, reading and re-writing with reduced size is a waste of IO / time
> - the patch seemed reasonable in size and intrusiveness -- I intentionally kept the implementation in a single function and avoided adding new types or passing maps or structs between phases and leveraged as much as llvm libraries as I could.
> - input .o come from a shared cache and have rich debug info and we're not using split-dwarf


Then how about `-gmlt`? If you compile the program (say `a.c`) twice, once with `-g` and once with `-gmlt`, then you link the program twice. The `-g` link gets full debug info, while the `-gmlt` link naturally gets smaller input and produces smaller output.

If you compile the program once with `-g`, and expect to get two programs, one with full debug info, the other with sufficient debug info to retain line tables. You can link it once and then postprocess the program with another tool.

In neither case a linker option is needed.

If you compile with `-g`, but never use the full debug info. This is the case that `--strip-debug-non-line` will become handy. However, why can't the program be compiled with `-gmlt` in the first place?

I tried digging up some history and it seems that --strip-debug-non-line may be a (legacy) solution that dated before `-gmlt` (`-g1`) and `-gsplit-dwarf`. My understanding is that with either compiler option, the linker option will become significantly less useful.



================
Comment at: lld/ELF/Driver.cpp:1853
+          .EndsWith("debug_str", false)
+          .StartsWith(".debug", true)
+          .StartsWith(".zdebug", true)
----------------
MaskRay wrote:
> ```
> if (S->Name.consume_front(".debug_") || S->Name.consume_front(".zdebug_")) {
>   ...
> }
> ```
This is not done.


================
Comment at: lld/ELF/Writer.cpp:1073
+template <typename value_type>
+void writeInt(raw_ostream &OS, value_type value, endianness endian) {
+  value = byte_swap<value_type>(value, endian);
----------------
MaskRay wrote:
> Delete this helper.
> 
> Use `endian::write(OS, UINT32_C(0xffffffff), Endian);` below.
> 
> (this utility is defined in llvm/Support/EndianStream.h)
This is not done.


================
Comment at: lld/ELF/Writer.cpp:1181
+
+      uint32_t NextInfoOffset = InfoOffset + Length;
+      uint16_t Version = InfoData.getU16(&InfoOffset);
----------------
MaskRay wrote:
> `NextInfoOffset` is only used once. Just `InfoOffset += Length` below.
This is not done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D46628/new/

https://reviews.llvm.org/D46628





More information about the llvm-commits mailing list