Skip to content

[LLD][COFF/ELF/Mach-O] Thin archives might reference objects by absolute paths in repro tarballs #97845

Open
@BertalanD

Description

@BertalanD

Thin archives' contents are copied verbatim into the repro tarballs; absolute paths to members don't get changed to be relative to the tarball's root.

I've only come across this problem because I was writing a test, and %t/foo.o expanded to an absolute path. Not sure if this could cause an issue in realistic cases.

This is a small test for it; modified from lld/test/MachO/reproduce-thin-archives.s (ld.lld is likely similarly affected by looking at the code):

# REQUIRES: x86

# RUN: rm -rf %t.dir
# RUN: mkdir -p %t.dir
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-macos %s -o %t.dir/foo.o
# RUN: llvm-ar rcsT %t.dir/foo.a %t.dir/foo.o

# RUN: cd %t.dir
# RUN: %lld foo.a -o /dev/null --reproduce repro.tar
## Remove the original object to make sure we are not using it.
# RUN: rm foo.o

# RUN: tar xf repro.tar
# RUN: cd repro
# RUN: %lld @response.txt

.globl _main
_main:
  nop

Running it gives:

ld64.lld: error: /Users/dani/Source/llvm-project/build/tools/lld/test/MachO/Output/reproduce-thin-archives.s.tmp.dir/foo.a: could not get the member defining symbol _main: '/Users/dani/Source/llvm-project/build/tools/lld/test/MachO/Output/reproduce-thin-archives.s.tmp.dir/foo.o': No such file or directory

When inspecting the archive in the repro file, indeed, the member is referred to by an absolute path:

$ llvm-ar t build/tools/lld/test/MachO/Output/reproduce-thin-archives.s.tmp.dir/repro/Users/dani/Source/llvm-project/build/tools/lld/test/MachO/Output/reproduce-thin-archives.s.tmp.dir/foo.a
/Users/dani/Source/llvm-project/build/tools/lld/test/MachO/Output/reproduce-thin-archives.s.tmp.dir/foo.o

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions