Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
BertalanD opened this issue Jul 5, 2024 · 2 comments

Comments

@BertalanD
Copy link
Member

BertalanD commented Jul 5, 2024

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
@llvmbot
Copy link
Member

llvmbot commented Jul 5, 2024

@llvm/issue-subscribers-lld-macho

Author: Daniel Bertalan (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; 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

@llvmbot
Copy link
Member

llvmbot commented Jul 5, 2024

@llvm/issue-subscribers-lld-elf

Author: Daniel Bertalan (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; 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

@nico nico changed the title [LLD][ELF/Mach-O] Thin archives might reference objects by absolute paths in repro tarballs [LLD][COFF/ELF/Mach-O] Thin archives might reference objects by absolute paths in repro tarballs Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants