apple-support-ar-wrapper: ar r drops the members already in the archive

Aperta
#685 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
42/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
cpp, macos
Ambito
build-system

Direzione di ricerca

Start with the ar mode handling in crosstool/libtool.cc, where the wrapper decides between a fresh libtool -static write and the q path that passes the existing archive back in. Reproduce with the two cr calls in an empty directory and check ar t lib.a; expected output is a.o b.o. Done means r, cr and crs keep earlier members with matching names, and the q behaviour from #670 still holds.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Since #601, apple-support-ar-wrapper accepts ar arguments. For r (with or without c, s, D) it runs libtool -static -D -o lib.a <new objects>, which writes a new archive. The members that an earlier call added are lost. The command exits 0, so the first sign is undefined symbols at link time.

#670 fixed the same problem for q: it passes the existing archive back to libtool as an input. That approach is not correct for r. r replaces each member that has the same name, so if the whole archive is passed back, the old member stays next to its replacement, and the linker takes the first one, which is the stale one.

Repro

Build the wrapper from the 2.11.0 tag (crosstool:exec_libtool, or xcrun clang -std=c++17 -lc++ -o apple-support-ar-wrapper crosstool/libtool.cc). Set DEVELOPER_DIR and SDKROOT (any values; the wrapper only requires them). Use any two objects a.o and b.o, and start each row of the table in an empty directory.

apple-support-ar-wrapper cr lib.a a.o
apple-support-ar-wrapper cr lib.a b.o
ar t lib.a

Expected: a.o and b.o. Actual: only b.o. (ar t also lists __.SYMDEF SORTED in both cases.)

Members after two calls (a.o, then b.o), from crosstool/libtool.cc at 2.11.0 and from /usr/bin/ar:

Mode wrapper /usr/bin/ar
r b.o a.o b.o
cr b.o a.o b.o
crs b.o a.o b.o
crD b.o (D not supported)
q a.o b.o a.o b.o
cq a.o b.o a.o b.o
Notes for a fix
  • ar r puts each new member in the place of the first old member with the same name, and appends the new members that replace nothing.
  • To match by name, the wrapper must name members after their files in ar mode, as ar does. Today it renames duplicate basenames to <stem>_<hash>.o.

Versions: apple_support 2.11.0, macOS 26.6.2 arm64, Xcode.

Lingua principale
Starlark
Stelle
109
Fork
79
Merge medio
4h 29m
PR unite (30g)
11

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bazelbuild/apple_support

Tutte le issue di bazelbuild/apple_support

Issue simili

Altre issue su Build System

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.