Skip to content

Commit 9c3a28a

Browse files
author
Alex B
committed
[lld-macho] Address Feedback #1
1 parent 35f02e4 commit 9c3a28a

File tree

11 files changed

+317
-359
lines changed

11 files changed

+317
-359
lines changed

lld/MachO/Driver.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ static InputFile *addFile(StringRef path, LoadType loadType,
340340
}
341341
} else if (isCommandLineLoad && config->forceLoadObjC) {
342342
for (const object::Archive::Symbol &sym : file->getArchive().symbols())
343-
if (sym.getName().starts_with(objc::klass))
343+
if (sym.getName().starts_with(objc::symbol_names::klass))
344344
file->fetch(sym);
345345

346346
// TODO: no need to look for ObjC sections for a given archive member if
@@ -395,7 +395,7 @@ static InputFile *addFile(StringRef path, LoadType loadType,
395395
if ((isa<ObjFile>(newFile) || isa<BitcodeFile>(newFile)) && newFile->lazy &&
396396
config->forceLoadObjC) {
397397
for (Symbol *sym : newFile->symbols)
398-
if (sym && sym->getName().starts_with(objc::klass)) {
398+
if (sym && sym->getName().starts_with(objc::symbol_names::klass)) {
399399
extract(*newFile, "-ObjC");
400400
break;
401401
}
@@ -1437,6 +1437,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
14371437
resetOutputSegments();
14381438
resetWriter();
14391439
InputFile::resetIdCount();
1440+
1441+
objc::doCleanup();
14401442
};
14411443

14421444
ctx->e.logName = args::getFilenameWithoutExe(argsArr[0]);
@@ -1984,6 +1986,8 @@ bool link(ArrayRef<const char *> argsArr, llvm::raw_ostream &stdoutOS,
19841986
if (args.hasArg(OPT_check_category_conflicts))
19851987
objc::checkCategories();
19861988

1989+
// Category merging uses "->live = false" to erase old category data, so
1990+
// it has to run after dead-stripping (markLive).
19871991
if (args.hasArg(OPT_objc_category_merging, OPT_no_objc_category_merging))
19881992
objc::mergeCategories();
19891993

lld/MachO/InputFiles.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1921,14 +1921,14 @@ DylibFile::DylibFile(const InterfaceFile &interface, DylibFile *umbrella,
19211921
case EncodeKind::ObjectiveCClass:
19221922
// XXX ld64 only creates these symbols when -ObjC is passed in. We may
19231923
// want to emulate that.
1924-
addSymbol(*symbol, objc::klass + symbol->getName());
1925-
addSymbol(*symbol, objc::metaclass + symbol->getName());
1924+
addSymbol(*symbol, objc::symbol_names::klass + symbol->getName());
1925+
addSymbol(*symbol, objc::symbol_names::metaclass + symbol->getName());
19261926
break;
19271927
case EncodeKind::ObjectiveCClassEHType:
1928-
addSymbol(*symbol, objc::ehtype + symbol->getName());
1928+
addSymbol(*symbol, objc::symbol_names::ehtype + symbol->getName());
19291929
break;
19301930
case EncodeKind::ObjectiveCInstanceVariable:
1931-
addSymbol(*symbol, objc::ivar + symbol->getName());
1931+
addSymbol(*symbol, objc::symbol_names::ivar + symbol->getName());
19321932
break;
19331933
}
19341934
}

lld/MachO/InputSection.h

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424
namespace lld {
2525
namespace macho {
2626

27-
enum LinkerOptReason : uint8_t {
28-
NotOptimized,
29-
CategoryMerging,
30-
};
31-
3227
class InputFile;
3328
class OutputSection;
3429

@@ -65,7 +60,6 @@ class InputSection {
6560
// Whether the data at \p off in this InputSection is live.
6661
virtual bool isLive(uint64_t off) const = 0;
6762
virtual void markLive(uint64_t off) = 0;
68-
virtual bool isLinkOptimizedAway() const { return false; }
6963
virtual InputSection *canonical() { return this; }
7064
virtual const InputSection *canonical() const { return this; }
7165

@@ -120,12 +114,7 @@ class ConcatInputSection final : public InputSection {
120114
bool isLive(uint64_t off) const override { return live; }
121115
void markLive(uint64_t off) override { live = true; }
122116
bool isCoalescedWeak() const { return wasCoalesced && symbols.empty(); }
123-
bool isLinkOptimizedAway() const override {
124-
return linkerOptimizeReason != LinkerOptReason::NotOptimized;
125-
}
126-
bool shouldOmitFromOutput() const {
127-
return isLinkOptimizedAway() || !live || isCoalescedWeak();
128-
}
117+
bool shouldOmitFromOutput() const { return !live || isCoalescedWeak(); }
129118
void writeTo(uint8_t *buf);
130119

131120
void foldIdentical(ConcatInputSection *redundant);
@@ -152,11 +141,6 @@ class ConcatInputSection final : public InputSection {
152141
// first and not copied to the output.
153142
bool wasCoalesced = false;
154143
bool live = !config->deadStrip;
155-
// Flag to specify if a linker optimzation flagged this section to be
156-
// discarded. Need a separate flag from live as live specifically means
157-
// 'dead-stripped' which is rellevant in contexts such as linker map
158-
// generation
159-
LinkerOptReason linkerOptimizeReason = LinkerOptReason::NotOptimized;
160144
bool hasCallSites = false;
161145
// This variable has two usages. Initially, it represents the input order.
162146
// After assignAddresses is called, it represents the offset from the
@@ -192,20 +176,10 @@ struct StringPiece {
192176
// Only set if deduplicating literals
193177
uint32_t hash : 31;
194178
// Offset from the start of the containing output section.
195-
uint64_t outSecOff : 48;
196-
// Have to declare the 'linkerOptimizeReason' and 'live' as uint64_t so that
197-
// the MSVC compiler will merge the storage of it and 'outSecOff' above.
198-
uint64_t /*LinkerOptReason*/ linkerOptimizeReason : 8;
199-
200-
bool shouldOmitFromOutput() const {
201-
return !live || linkerOptimizeReason != LinkerOptReason::NotOptimized;
202-
}
179+
uint64_t outSecOff = 0;
203180

204181
StringPiece(uint64_t off, uint32_t hash)
205-
: inSecOff(off), live(!config->deadStrip), hash(hash) {
206-
outSecOff = 0;
207-
linkerOptimizeReason = LinkerOptReason::NotOptimized;
208-
}
182+
: inSecOff(off), live(!config->deadStrip), hash(hash) {}
209183
};
210184

211185
static_assert(sizeof(StringPiece) == 16, "StringPiece is too big!");

lld/MachO/MapFile.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ static MapInfo gatherMapInfo() {
8080
if (d->isec && d->getFile() == file &&
8181
!isa<CStringInputSection>(d->isec)) {
8282
isReferencedFile = true;
83-
if (!d->isLive() && (!d->isec || !d->isec->isLinkOptimizedAway()))
83+
if (!d->isLive())
8484
info.deadSymbols.push_back(d);
8585
}
8686
}
@@ -93,8 +93,6 @@ static MapInfo gatherMapInfo() {
9393
if (auto isec = dyn_cast<CStringInputSection>(subsec.isec)) {
9494
auto &liveCStrings = info.liveCStringsForSection[isec->parent];
9595
for (const auto &[i, piece] : llvm::enumerate(isec->pieces)) {
96-
if (piece.linkerOptimizeReason != LinkerOptReason::NotOptimized)
97-
continue;
9896
if (piece.live)
9997
liveCStrings.push_back({isec->parent->addr + piece.outSecOff,
10098
{fileIndex, isec->getStringRef(i)}});
@@ -205,8 +203,6 @@ void macho::writeMapFile() {
205203
for (const OutputSection *osec : seg->getSections()) {
206204
if (auto *concatOsec = dyn_cast<ConcatOutputSection>(osec)) {
207205
for (const InputSection *isec : concatOsec->inputs) {
208-
if (isec->isLinkOptimizedAway())
209-
continue;
210206
for (Defined *sym : isec->symbols)
211207
if (!(isPrivateLabel(sym->getName()) && sym->size == 0))
212208
os << format("0x%08llX\t0x%08llX\t[%3u] %s\n", sym->getVA(),

lld/MachO/MarkLive.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,6 @@ void markLive() {
259259
dyn_cast_or_null<DylibSymbol>(symtab->find("dyld_stub_binder")))
260260
marker->addSym(stubBinder);
261261
for (ConcatInputSection *isec : inputSections) {
262-
if (isec->isLinkOptimizedAway())
263-
continue;
264262
// Sections marked no_dead_strip
265263
if (isec->getFlags() & S_ATTR_NO_DEAD_STRIP) {
266264
marker->enqueue(isec, 0);

0 commit comments

Comments
 (0)