[lld] [lld][ELF] Add --debug-names to create merged .debug_names. (PR #86508)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 11 11:13:20 PDT 2024


MaskRay wrote:

I am involved in the code, so I am biased happy:) I'd hope other reviewers can look at the code as well.

I think this PR will be pretty good if some test changes are made.

* Missing 32-bit and big-endian tests. We can add a variant of `debug-names.s` that targets 32-bit PowerPC (`llvm-mc -triple=powerpc`, `clang --target=powerpc`)
* I've modified the test files to check `[[FILE]]` in the error message. Ideally, edit one or two negative test files to additionally test `--noinhibit-exec` (downgrade recoverable errors to warnings. Ensure that we create an output despite recoverable errors.)
* Missing tests for `comp_unit_count>1`. We can enhance `debug-names.s` to test the scenario. See detailed instructions below.

Some improvements that I'd like to see:

* Test files don't need to have `debug-names-` prefixes. They make RUN lines longer without adding clarity. In many tests we just use `a.s`, `b.s`, `c.s`, etc.
* Ideally, group very similar negative tests together. https://maskray.me/blog/2021-08-08-toolchain-testing#the-test-checks-at-the-wrong-layer#i-dont-know-an-existing-test-can-be-enhanced
  We can use `sed` to make small changes. A simple sed command is even more readable than a textual comment "change X to Y".


Prepare a.cpp (defines `_start` and others), b.cpp, and c.cpp. We will link them together.

PATH=/tmp/Rel/bin:$PATH
clang -c -O1 -flto -g -gpubnames -fdebug-compilation-dir=/proc/self/cwd a.cpp b.cpp
clang -O1 -flto -g -gpubnames -fdebug-compilation-dir=/proc/self/cwd a.cpp b.cpp -nostdlib -fuse-ld=lld -Wl,--lto-emit-asm -o ab

# use ab.lto.s an input file to debug-names.s

clang -S -flto -g -gpubnames -gsplit-dwarf -fdebug-compilation-dir=/proc/self/cwd c.cpp
# c.s  # use as another input file to debug-names.s

# rewrite debug-names.s, assemble ab.lto.s and c.s with llvm-mc and link them together.

---

```
RUN: rm -rf %t && split-file %s %t && cd %t
RUN: llvm-mc -filetype=obj -triple=x86_64 a.s -o a.o

RUN: sed '/SED bad_die_offset/{n; s/3/4/}' a.s -o bad_die_offset.o
RUN: not ld.lld bad_die_offset.o 2>&1 | FileCheck %s --check-prefix=ERR1

RUN: sed '/SED bad_form_for_die_offset/{n; s/3/4/}' a.s -o bad_form_for_die_offset.o
RUN: not ld.lld bad_form_for_die_offset.o 2>&1 | FileCheck %s --check-prefix=ERR1

ERR1: error: ...


## SED bad_die_offset
	.byte	3                               # DW_IDX_die_offset
## SED bad_form_for_die_offset
        .byte   25                               DW_FORM_flag_present
```


https://github.com/llvm/llvm-project/pull/86508


More information about the llvm-commits mailing list