Hi Andrii,

On Tue, Nov 24, 2026 at 4:37 PM Andrii Nakryiko <[email protected]> wrote:
>
> Build systems that make builds reproducible, like Buck, run the
> compiler with a relative compilation directory, usually ".", for
> example with -fdebug-compilation-dir=. or -fdebug-prefix-map=$PWD=., so
> that the absolute build directory doesn't end up in the output.  A
> skeleton unit then has DW_AT_comp_dir "." and a DW_AT_dwo_name that is
> relative to the directory that the build ran in, like
> "buck-out/v2/.../foo.dwo", while the binary is in another directory.
>
> __libdw_find_split_unit only looks for .dwo files relative to the
> directory of the binary.  It tries DW_AT_dwo_name, and DW_AT_comp_dir
> plus DW_AT_dwo_name, both relative to that directory.  So it doesn't
> find these .dwo files, and dwarf_get_units and dwarf_cu_info return no
> split unit for the skeleton.
>
> GDB, LLDB, and LLVM also look in the current working directory, so
> they find these .dwo files when they run in the directory that the
> build ran in.  GDB tries DW_AT_comp_dir plus DW_AT_dwo_name, and
> DW_AT_dwo_name, there.  LLVM's DWARF library, used by llvm-dwarfdump
> and llvm-symbolizer, tries DW_AT_comp_dir plus DW_AT_dwo_name there.
> LLDB tries DW_AT_dwo_name there.  (Checked with GDB 17.2,
> llvm-dwarfdump 21, and LLDB 24.)
>
> Do the same as GDB and LLVM: if the .dwo file isn't found relative to
> the directory of the binary, try a relative DW_AT_comp_dir plus
> DW_AT_dwo_name, or a relative DW_AT_dwo_name if there is no
> DW_AT_comp_dir, relative to the current working directory.
>
>         * libdw/libdw_find_split_unit.c (__libdw_find_split_unit): Try a
>         relative compdir plus dwo_name in the current working directory.
>         * tests/testfile-relative-compdir.bz2: New test file.
>         * tests/testfile-relative-compdir.dwo.bz2: New test file.
>         * tests/testfile-relative-compdir.source: New file.
>         * tests/run-get-units-split.sh: Check testfile-relative-compdir
>         with its .dwo file in the current working directory instead of
>         next to the binary.
>         * tests/Makefile.am (EXTRA_DIST): Add
>         testfile-relative-compdir.bz2,
>         testfile-relative-compdir.dwo.bz2, and
>         testfile-relative-compdir.source.
>
> Signed-off-by: Andrii Nakryiko <[email protected]>

Thanks for the patch, pushed.

Aaron

> ---
>  libdw/libdw_find_split_unit.c           |  18 +++++++++++++++++-
>  tests/Makefile.am                       |   3 +++
>  tests/run-get-units-split.sh            |  15 +++++++++++++++
>  tests/testfile-relative-compdir.bz2     | Bin 0 -> 2838 bytes
>  tests/testfile-relative-compdir.dwo.bz2 | Bin 0 -> 630 bytes
>  tests/testfile-relative-compdir.source  |  16 ++++++++++++++++
>  6 files changed, 51 insertions(+), 1 deletion(-)
>  create mode 100644 tests/testfile-relative-compdir.bz2
>  create mode 100644 tests/testfile-relative-compdir.dwo.bz2
>  create mode 100644 tests/testfile-relative-compdir.source
>
> diff --git a/libdw/libdw_find_split_unit.c b/libdw/libdw_find_split_unit.c
> index a77a6bbbbd6b..073c01f67669 100644
> --- a/libdw/libdw_find_split_unit.c
> +++ b/libdw/libdw_find_split_unit.c
> @@ -217,7 +217,8 @@ __libdw_find_split_unit (Dwarf_CU *cu)
>        Dwarf_Die cudie = CUDIE (cu);
>        Dwarf_Attribute dwo_name;
>        /* Try a dwo file.  It is fine if dwo_dir doesn't exist, but then
> -        dwo_name needs to be an absolute path.  */
> +        dwo_name needs to be an absolute path or relative to the current
> +        working directory.  */
>        if (cu->split == (Dwarf_CU *) -1
>           && (dwarf_attr (&cudie, DW_AT_dwo_name, &dwo_name) != NULL
>               || dwarf_attr (&cudie, DW_AT_GNU_dwo_name, &dwo_name) != NULL))
> @@ -248,6 +249,21 @@ __libdw_find_split_unit (Dwarf_CU *cu)
>                       free (dwo_path);
>                     }
>                 }
> +
> +             /* Try a relative compdir plus dwo_name, or a relative
> +                dwo_name without compdir, in the current working
> +                directory.  */
> +             if (cu->split == (Dwarf_CU *) -1
> +                 && dwo_file != NULL && dwo_file[0] != '/'
> +                 && (dwo_dir == NULL || dwo_dir[0] != '/'))
> +               {
> +                 dwo_path = __libdw_filepath ("./", dwo_dir, dwo_file);
> +                 if (dwo_path != NULL)
> +                   {
> +                     try_split_file (cu, dwo_path);
> +                     free (dwo_path);
> +                   }
> +               }
>             }
>           /* XXX If still not found we could try stripping dirs from the
>              comp_dir and adding them from the comp_dir, assuming
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 98b267f520fd..b8971d9630d5 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -750,6 +750,9 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \
>              testfile-dwp-4-cu-index-overflow.bz2 \
>              testfile-dwp-4-cu-index-overflow.dwp.bz2 \
>              testfile-dwp-cu-index-overflow.source \
> +            testfile-relative-compdir.bz2 \
> +            testfile-relative-compdir.dwo.bz2 \
> +            testfile-relative-compdir.source \
>              testfile-define-file.bz2 \
>              testfile-sysroot.tar.bz2 run-sysroot.sh \
>              run-test-manyfuncs.sh manyfuncs.c \
> diff --git a/tests/run-get-units-split.sh b/tests/run-get-units-split.sh
> index 52361fa8f874..3c5146f30393 100755
> --- a/tests/run-get-units-split.sh
> +++ b/tests/run-get-units-split.sh
> @@ -86,4 +86,19 @@ Found a skeleton unit, with split die: main.cc
>  EOF
>  done
>
> +# See testfile-relative-compdir.source.  DW_AT_comp_dir is "." and
> +# DW_AT_dwo_name is relative, so the .dwo file is found in the current
> +# working directory even though the binary is in another directory.
> +testfiles testfile-relative-compdir testfile-relative-compdir.dwo
> +mkdir bin
> +mv testfile-relative-compdir bin/
> +testrun_compare ${abs_builddir}/get-units-split 
> bin/testfile-relative-compdir << EOF
> +file: bin/testfile-relative-compdir
> +Got cudie unit_type: 4
> +Found a skeleton unit, with split die: hello.c
> +
> +EOF
> +rm bin/testfile-relative-compdir
> +rmdir bin
> +
>  exit 0
> diff --git a/tests/testfile-relative-compdir.bz2 
> b/tests/testfile-relative-compdir.bz2
> new file mode 100644
> index 
> 0000000000000000000000000000000000000000..11c18a9674f08581fc83aa4e892dee16a3f6c184
> GIT binary patch
> literal 2838
> zcmV+x3+ePiT4*^jL0KkKS+MvPdH@Ug|NsC0|NsC0|NsB@|NsB@|M%~{eS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Rw+aoyv
> zyELyRNXW%aSXn`rz(JH7jJio@3#Ldy1R%h%Q9dRLAgV({gjZEnp{ZN;r>Qdv2_qr<
> zan9SS=U0njF~YnsyIn(e<PyofiRD_XFvuXf!h|OZLK<i=KQ~FCbCqwxuwrFc76D)*
> z7DzP%6EWq+r07)Tm%!rAcm~C5dW(wErKJNT49dvC#u2y&SgCSIZ41qrZV-CVNlszl
> zaWM$Bj<5y5;(#YZ9<-<32V;9?A&~}T(wNLDA^|W$B$AWfC?<f=7=p=e-0fu=kbNOb
> z&#z2FKtm?ytANv9^-UO2V>Ac?z!r)+JE{9;qr2GawkT{SA`_7!Sq8;9Kc=;y#JEV`
> z(_uhiLBh3C(I7w!I}aw4!z?lw&5g>75*EV5hr9UVfs9L5)sjppYP8$SKL&OZ(P^@i
> zZRARAuZ98TP_6qt9#`Fijc@HTX6IkJvJ_rM^zlyNjr+B!i&V;w(BA@|G4cozUWk?%
> o&95#8_~cCrglo`>NfI^B`gY~SdZQI2L#h5Q<ce^iAz|<=^lTUF*8l(j
>
> literal 0
> HcmV?d00001
>
> diff --git a/tests/testfile-relative-compdir.dwo.bz2 
> b/tests/testfile-relative-compdir.dwo.bz2
> new file mode 100644
> index 
> 0000000000000000000000000000000000000000..7d85c089a77d17a5a3fde08976d19f6a379270b9
> GIT binary patch
> literal 630
> zcmV-+0*U=XT4*^jL0KkKSsevq=>P$+f9e0~xc+AAfB*02w~fE&|M0|+L<|rBKtNF-
> zKmo@)u4+R>M8HX=O*CnQ7)>z%$TR_<$k1W{$PF19dO@NlrV3_3Jv5)GGynhq4@dw2
> zXwU!v9#9PvMG$F(dW|&6lSYjI(8S565NKgCXaF=c8W|d4rj<<%7>zX0(@c#tVl>EP
> z42*+ACYS(&MvMdiP+>Z1pv;M7?qV&0d#y0f$qR|8%||NIq)(s*QVkFD{9e<{uRfBx
> zSqS1o)Q(dCWXM4Qom!G)Rz#B`0~p8&b0(&Fv}9OC6JUS@B7<arq$xlEs!$RWq2jYB
> zqyl3R=urkC36?-s3KXRl3J~Zj2xI}k3{rpwr8VmkFzpt8DDe#aeH7b)L^^J-UvP<l
> z&6uoVtc*rb%tg%5b)gd5WWw9<@sUMX)ajz&-7!4KhHTfsNUUlyF*yLIn?_F@D1wb<
> z5W;D(HrAlPV-U#<fNCgqfO4IB>U0)WAUc!~QG@`wx7gw68jlx5&${(qRWh*5HU=w5
> ze{Y92Z$+9L^Qpy+74(>im1PX!rAEvPD+y1<fkdGY)JCmKYK?=SA~?vHEA!LqmZ&3v
> z+@~dr4Wyx`z87?>z?I)3kDF-<wRszgp&Jr49~#RruGL<o+l2<x)(_Q2;JSZBFvQ}y
> zdKvzP1<Rmy#~~z|yyEm_N+AO%A;>d`e7;I!A=1fCWMmk3ywRi|S-8ar=|qHAu_TjD
> z$Z&_HAS{C=HOQVhl>yT*97vpPE*AwPh+BFAQQ#ay(hfGH2!v4Aml^;o_t5OQZo?7q
> QD6jatk}1N3faoh9NP(yk9RL6T
>
> literal 0
> HcmV?d00001
>
> diff --git a/tests/testfile-relative-compdir.source 
> b/tests/testfile-relative-compdir.source
> new file mode 100644
> index 000000000000..57df32f47527
> --- /dev/null
> +++ b/tests/testfile-relative-compdir.source
> @@ -0,0 +1,16 @@
> +# Program used to generate a split DWARF file with a relative DW_AT_comp_dir,
> +# like build systems that make the build directory "." for reproducible 
> builds.
> +
> +# = hello.c =
> +
> +int
> +main (int argc, char **argv)
> +{
> +  return argc - 1;
> +}
> +
> +# Built with GCC 11.5.0.  The skeleton unit has DW_AT_comp_dir "." and
> +# DW_AT_dwo_name "testfile-relative-compdir.dwo".
> +$ gcc -gdwarf-5 -gsplit-dwarf -fdebug-prefix-map=$PWD=. -O2 -c hello.c \
> +    -o testfile-relative-compdir.o
> +$ gcc testfile-relative-compdir.o -o testfile-relative-compdir
> --
> 2.53.1-Meta
>

Reply via email to