[Bug 50770] New: lldb/mac can't load object files from thin archives

Bug ID 50770
Summary lldb/mac can’t load object files from thin archives
Product lldb
Version unspecified
Hardware PC
OS All
Status NEW
Severity enhancement
Priority P
Component All Bugs
Assignee lldb-dev@lists.llvm.org
Reporter nicolasweber@gmx.de
CC jdevlieghere@apple.com, llvm-bugs@lists.llvm.org

lld/mac and llvm-ar support thin archives (where the .a file just stores an
index of symbols and then links to .o files on-disk for data).

Thin archives confuse lldb:

% cat foo.c
#include <stdio.h>
void foo() { printf("asdf\n"); }

% clang -c -g foo.c

% cat mainfoo.c
void foo();
int main() { foo(); }

% clang -c -g mainfoo.c

## -T here makes llvm-ar create a thin archive:
% rm -f libfoo.a && out/gn/bin/llvm-ar -rcsDT libfoo.a foo.o

% out/gn/bin/clang -fuse-ld=lld mainfoo.o libfoo.a

% lldb a.out
(lldb) target create "a.out"
Current executable set to '/Users/thakis/src/llvm-project/a.out' (x86_64).
(lldb) b main
error: libfoo.a(foo.o) failed to load objfile for

This works fine with a non-thin archive.

(Remember to rm the .a file before re-running llvm-ar since the thin archive
flag seems to be sticky.)