152 changes: 135 additions & 17 deletions lld/MachO/SyntheticSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ void MachHeaderSection::writeTo(uint8_t *buf) const {
if (config->outputType == MachO::MH_DYLIB && !config->hasReexports)
hdr->flags |= MachO::MH_NO_REEXPORTED_DYLIBS;

if (config->outputType == MachO::MH_EXECUTE && config->isPic)
hdr->flags |= MachO::MH_PIE;

if (in.exports->hasWeakSymbol || in.weakBinding->hasNonWeakDefinition())
hdr->flags |= MachO::MH_WEAK_DEFINES;

Expand All @@ -88,6 +91,97 @@ void MachHeaderSection::writeTo(uint8_t *buf) const {
PageZeroSection::PageZeroSection()
: SyntheticSection(segment_names::pageZero, section_names::pageZero) {}

uint64_t Location::getVA() const {
if (const auto *isec = section.dyn_cast<const InputSection *>())
return isec->getVA() + offset;
return section.get<const OutputSection *>()->addr + offset;
}

RebaseSection::RebaseSection()
: LinkEditSection(segment_names::linkEdit, section_names::rebase) {}

namespace {
struct Rebase {
OutputSegment *segment = nullptr;
uint64_t offset = 0;
uint64_t consecutiveCount = 0;
};
} // namespace

// Rebase opcodes allow us to describe a contiguous sequence of rebase location
// using a single DO_REBASE opcode. To take advantage of it, we delay emitting
// `DO_REBASE` until we have reached the end of a contiguous sequence.
static void encodeDoRebase(Rebase &rebase, raw_svector_ostream &os) {
using namespace llvm::MachO;
assert(rebase.consecutiveCount != 0);
if (rebase.consecutiveCount <= REBASE_IMMEDIATE_MASK) {
os << static_cast<uint8_t>(REBASE_OPCODE_DO_REBASE_IMM_TIMES |
rebase.consecutiveCount);
} else {
os << static_cast<uint8_t>(REBASE_OPCODE_DO_REBASE_ULEB_TIMES);
encodeULEB128(rebase.consecutiveCount, os);
}
rebase.consecutiveCount = 0;
}

static void encodeRebase(const OutputSection *osec, uint64_t outSecOff,
Rebase &lastRebase, raw_svector_ostream &os) {
using namespace llvm::MachO;
OutputSegment *seg = osec->parent;
uint64_t offset = osec->getSegmentOffset() + outSecOff;
if (lastRebase.segment != seg || lastRebase.offset != offset) {
if (lastRebase.consecutiveCount != 0)
encodeDoRebase(lastRebase, os);

if (lastRebase.segment != seg) {
os << static_cast<uint8_t>(REBASE_OPCODE_SET_SEGMENT_AND_OFFSET_ULEB |
seg->index);
encodeULEB128(offset, os);
lastRebase.segment = seg;
lastRebase.offset = offset;
} else {
assert(lastRebase.offset != offset);
os << static_cast<uint8_t>(REBASE_OPCODE_ADD_ADDR_ULEB);
encodeULEB128(offset - lastRebase.offset, os);
lastRebase.offset = offset;
}
}
++lastRebase.consecutiveCount;
// DO_REBASE causes dyld to both perform the binding and increment the offset
lastRebase.offset += WordSize;
}

void RebaseSection::finalizeContents() {
using namespace llvm::MachO;
if (locations.empty())
return;

raw_svector_ostream os{contents};
Rebase lastRebase;

os << static_cast<uint8_t>(REBASE_OPCODE_SET_TYPE_IMM | REBASE_TYPE_POINTER);

llvm::sort(locations, [](const Location &a, const Location &b) {
return a.getVA() < b.getVA();
});
for (const Location &loc : locations) {
if (const auto *isec = loc.section.dyn_cast<const InputSection *>()) {
encodeRebase(isec->parent, isec->outSecOff + loc.offset, lastRebase, os);
} else {
const auto *osec = loc.section.get<const OutputSection *>();
encodeRebase(osec, loc.offset, lastRebase, os);
}
}
if (lastRebase.consecutiveCount != 0)
encodeDoRebase(lastRebase, os);

os << static_cast<uint8_t>(REBASE_OPCODE_DONE);
}

void RebaseSection::writeTo(uint8_t *buf) const {
memcpy(buf, contents.data(), contents.size());
}

NonLazyPointerSectionBase::NonLazyPointerSectionBase(const char *segname,
const char *name)
: SyntheticSection(segname, name) {
Expand Down Expand Up @@ -184,12 +278,6 @@ static void encodeWeakOverride(const Defined *defined,
<< defined->getName() << '\0';
}

uint64_t BindingTarget::getVA() const {
if (auto *isec = section.dyn_cast<const InputSection *>())
return isec->getVA() + offset;
return section.get<const OutputSection *>()->addr + offset;
}

// Emit bind opcodes, which are a stream of byte-sized opcodes that dyld
// interprets to update a record with the following fields:
// * segment index (of the segment to write the symbol addresses to, typically
Expand Down Expand Up @@ -217,11 +305,10 @@ void BindingSection::finalizeContents() {
encodeDylibOrdinal(b.dysym, lastBinding, os);
if (auto *isec = b.target.section.dyn_cast<const InputSection *>()) {
encodeBinding(b.dysym, isec->parent, isec->outSecOff + b.target.offset,
b.target.addend, lastBinding, os);
b.addend, lastBinding, os);
} else {
auto *osec = b.target.section.get<const OutputSection *>();
encodeBinding(b.dysym, osec, b.target.offset, b.target.addend,
lastBinding, os);
encodeBinding(b.dysym, osec, b.target.offset, b.addend, lastBinding, os);
}
}
if (!bindings.empty())
Expand Down Expand Up @@ -251,11 +338,10 @@ void WeakBindingSection::finalizeContents() {
for (const WeakBindingEntry &b : bindings) {
if (auto *isec = b.target.section.dyn_cast<const InputSection *>()) {
encodeBinding(b.symbol, isec->parent, isec->outSecOff + b.target.offset,
b.target.addend, lastBinding, os);
b.addend, lastBinding, os);
} else {
auto *osec = b.target.section.get<const OutputSection *>();
encodeBinding(b.symbol, osec, b.target.offset, b.target.addend,
lastBinding, os);
encodeBinding(b.symbol, osec, b.target.offset, b.addend, lastBinding, os);
}
}
if (!bindings.empty() || !definitions.empty())
Expand Down Expand Up @@ -284,6 +370,7 @@ void macho::addNonLazyBindingEntries(const Symbol *sym,
if (dysym->isWeakDef())
in.weakBinding->addEntry(sym, section, offset, addend);
} else if (auto *defined = dyn_cast<Defined>(sym)) {
in.rebase->addEntry(section, offset);
if (defined->isWeakDef() && defined->isExternal())
in.weakBinding->addEntry(sym, section, offset, addend);
} else if (isa<DSOHandle>(sym)) {
Expand Down Expand Up @@ -407,8 +494,10 @@ void LazyBindingSection::writeTo(uint8_t *buf) const {
}

void LazyBindingSection::addEntry(DylibSymbol *dysym) {
if (entries.insert(dysym))
if (entries.insert(dysym)) {
dysym->stubsHelperIndex = entries.size() - 1;
in.rebase->addEntry(in.lazyPointers, dysym->stubsIndex * WordSize);
}
}

// Unlike the non-lazy binding section, the bind opcodes in this section aren't
Expand Down Expand Up @@ -440,6 +529,29 @@ uint32_t LazyBindingSection::encode(const DylibSymbol &sym) {
return opstreamOffset;
}

void macho::prepareBranchTarget(Symbol *sym) {
if (auto *dysym = dyn_cast<DylibSymbol>(sym)) {
if (in.stubs->addEntry(dysym)) {
if (sym->isWeakDef()) {
in.binding->addEntry(dysym, in.lazyPointers,
sym->stubsIndex * WordSize);
in.weakBinding->addEntry(sym, in.lazyPointers,
sym->stubsIndex * WordSize);
} else {
in.lazyBinding->addEntry(dysym);
}
}
} else if (auto *defined = dyn_cast<Defined>(sym)) {
if (defined->isWeakDef() && defined->isExternal()) {
if (in.stubs->addEntry(sym)) {
in.rebase->addEntry(in.lazyPointers, sym->stubsIndex * WordSize);
in.weakBinding->addEntry(sym, in.lazyPointers,
sym->stubsIndex * WordSize);
}
}
}
}

ExportSection::ExportSection()
: LinkEditSection(segment_names::linkEdit, section_names::export_) {}

Expand Down Expand Up @@ -482,11 +594,17 @@ void SymtabSection::writeTo(uint8_t *buf) const {
// TODO support other symbol types
// TODO populate n_desc with more flags
if (auto *defined = dyn_cast<Defined>(entry.sym)) {
nList->n_type = MachO::N_EXT | MachO::N_SECT;
nList->n_sect = defined->isec->parent->index;
if (defined->isAbsolute()) {
nList->n_type = MachO::N_EXT | MachO::N_ABS;
nList->n_sect = MachO::NO_SECT;
nList->n_value = defined->value;
} else {
nList->n_type = MachO::N_EXT | MachO::N_SECT;
nList->n_sect = defined->isec->parent->index;
// For the N_SECT symbol type, n_value is the address of the symbol
nList->n_value = defined->value + defined->isec->getVA();
}
nList->n_desc |= defined->isWeakDef() ? MachO::N_WEAK_DEF : 0;
// For the N_SECT symbol type, n_value is the address of the symbol
nList->n_value = defined->value + defined->isec->getVA();
}
++nList;
}
Expand Down
57 changes: 42 additions & 15 deletions lld/MachO/SyntheticSections.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ namespace section_names {
constexpr const char pageZero[] = "__pagezero";
constexpr const char common[] = "__common";
constexpr const char header[] = "__mach_header";
constexpr const char rebase[] = "__rebase";
constexpr const char binding[] = "__binding";
constexpr const char weakBinding[] = "__weak_binding";
constexpr const char lazyBinding[] = "__lazy_binding";
Expand Down Expand Up @@ -153,22 +154,42 @@ class TlvPointerSection : public NonLazyPointerSectionBase {
using SectionPointerUnion =
llvm::PointerUnion<const InputSection *, const OutputSection *>;

struct BindingTarget {
SectionPointerUnion section;
uint64_t offset;
int64_t addend;

BindingTarget(SectionPointerUnion section, uint64_t offset, int64_t addend)
: section(section), offset(offset), addend(addend) {}
struct Location {
SectionPointerUnion section = nullptr;
uint64_t offset = 0;

Location(SectionPointerUnion section, uint64_t offset)
: section(section), offset(offset) {}
uint64_t getVA() const;
};

// Stores rebase opcodes, which tell dyld where absolute addresses have been
// encoded in the binary. If the binary is not loaded at its preferred address,
// dyld has to rebase these addresses by adding an offset to them.
class RebaseSection : public LinkEditSection {
public:
RebaseSection();
void finalizeContents();
uint64_t getRawSize() const override { return contents.size(); }
bool isNeeded() const override { return !locations.empty(); }
void writeTo(uint8_t *buf) const override;

void addEntry(SectionPointerUnion section, uint64_t offset) {
if (config->isPic)
locations.push_back({section, offset});
}

private:
std::vector<Location> locations;
SmallVector<char, 128> contents;
};

struct BindingEntry {
const DylibSymbol *dysym;
BindingTarget target;
BindingEntry(const DylibSymbol *dysym, BindingTarget target)
: dysym(dysym), target(std::move(target)) {}
int64_t addend;
Location target;
BindingEntry(const DylibSymbol *dysym, int64_t addend, Location target)
: dysym(dysym), addend(addend), target(std::move(target)) {}
};

// Stores bind opcodes for telling dyld which symbols to load non-lazily.
Expand All @@ -182,7 +203,7 @@ class BindingSection : public LinkEditSection {

void addEntry(const DylibSymbol *dysym, SectionPointerUnion section,
uint64_t offset, int64_t addend = 0) {
bindings.emplace_back(dysym, BindingTarget(section, offset, addend));
bindings.emplace_back(dysym, addend, Location(section, offset));
}

private:
Expand All @@ -192,9 +213,10 @@ class BindingSection : public LinkEditSection {

struct WeakBindingEntry {
const Symbol *symbol;
BindingTarget target;
WeakBindingEntry(const Symbol *symbol, BindingTarget target)
: symbol(symbol), target(std::move(target)) {}
int64_t addend;
Location target;
WeakBindingEntry(const Symbol *symbol, int64_t addend, Location target)
: symbol(symbol), addend(addend), target(std::move(target)) {}
};

// Stores bind opcodes for telling dyld which weak symbols need coalescing.
Expand All @@ -220,7 +242,7 @@ class WeakBindingSection : public LinkEditSection {

void addEntry(const Symbol *symbol, SectionPointerUnion section,
uint64_t offset, int64_t addend = 0) {
bindings.emplace_back(symbol, BindingTarget(section, offset, addend));
bindings.emplace_back(symbol, addend, Location(section, offset));
}

bool hasEntry() const { return !bindings.empty(); }
Expand Down Expand Up @@ -342,6 +364,10 @@ class LazyBindingSection : public LinkEditSection {
llvm::raw_svector_ostream os{contents};
};

// Adds stubs and bindings where necessary (e.g. if the symbol is a
// DylibSymbol.)
void prepareBranchTarget(Symbol *);

// Stores a trie that describes the set of exported symbols.
class ExportSection : public LinkEditSection {
public:
Expand Down Expand Up @@ -416,6 +442,7 @@ class IndirectSymtabSection : public LinkEditSection {

struct InStruct {
MachHeaderSection *header = nullptr;
RebaseSection *rebase = nullptr;
BindingSection *binding = nullptr;
WeakBindingSection *weakBinding = nullptr;
LazyBindingSection *lazyBinding = nullptr;
Expand Down
39 changes: 34 additions & 5 deletions lld/MachO/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ class Writer {
// LC_DYLD_INFO_ONLY stores the offsets of symbol import/export information.
class LCDyldInfo : public LoadCommand {
public:
LCDyldInfo(BindingSection *bindingSection,
LCDyldInfo(RebaseSection *rebaseSection, BindingSection *bindingSection,
WeakBindingSection *weakBindingSection,
LazyBindingSection *lazyBindingSection,
ExportSection *exportSection)
: bindingSection(bindingSection), weakBindingSection(weakBindingSection),
: rebaseSection(rebaseSection), bindingSection(bindingSection),
weakBindingSection(weakBindingSection),
lazyBindingSection(lazyBindingSection), exportSection(exportSection) {}

uint32_t getSize() const override { return sizeof(dyld_info_command); }
Expand All @@ -80,6 +81,10 @@ class LCDyldInfo : public LoadCommand {
auto *c = reinterpret_cast<dyld_info_command *>(buf);
c->cmd = LC_DYLD_INFO_ONLY;
c->cmdsize = getSize();
if (rebaseSection->isNeeded()) {
c->rebase_off = rebaseSection->fileOff;
c->rebase_size = rebaseSection->getFileSize();
}
if (bindingSection->isNeeded()) {
c->bind_off = bindingSection->fileOff;
c->bind_size = bindingSection->getFileSize();
Expand All @@ -98,6 +103,7 @@ class LCDyldInfo : public LoadCommand {
}
}

RebaseSection *rebaseSection;
BindingSection *bindingSection;
WeakBindingSection *weakBindingSection;
LazyBindingSection *lazyBindingSection;
Expand Down Expand Up @@ -188,7 +194,13 @@ class LCMain : public LoadCommand {
auto *c = reinterpret_cast<entry_point_command *>(buf);
c->cmd = LC_MAIN;
c->cmdsize = getSize();
c->entryoff = config->entry->getFileOffset();

if (config->entry->isInStubs())
c->entryoff =
in.stubs->fileOff + config->entry->stubsIndex * target->stubSize;
else
c->entryoff = config->entry->getFileOffset();

c->stacksize = 0;
}
};
Expand Down Expand Up @@ -333,21 +345,31 @@ class LCBuildVersion : public LoadCommand {

void Writer::scanRelocations() {
for (InputSection *isec : inputSections) {
// We do not wish to add rebase opcodes for __LD,__compact_unwind, because
// it doesn't actually end up in the final binary. TODO: filtering it out
// before Writer runs might be cleaner...
if (isec->segname == segment_names::ld)
continue;

for (Reloc &r : isec->relocs) {
if (auto *s = r.referent.dyn_cast<lld::macho::Symbol *>()) {
if (isa<Undefined>(s))
error("undefined symbol " + s->getName() + ", referenced from " +
sys::path::filename(isec->file->getName()));
else
target->prepareSymbolRelocation(s, isec, r);
} else {
assert(r.referent.is<InputSection *>());
if (!r.pcrel)
in.rebase->addEntry(isec, r.offset);
}
}
}
}

void Writer::createLoadCommands() {
in.header->addLoadCommand(
make<LCDyldInfo>(in.binding, in.weakBinding, in.lazyBinding, in.exports));
in.header->addLoadCommand(make<LCDyldInfo>(
in.rebase, in.binding, in.weakBinding, in.lazyBinding, in.exports));
in.header->addLoadCommand(make<LCSymtab>(symtabSection, stringTableSection));
in.header->addLoadCommand(make<LCDysymtab>(indirectSymtabSection));
for (StringRef path : config->runtimePaths)
Expand All @@ -361,6 +383,8 @@ void Writer::createLoadCommands() {
case MH_DYLIB:
in.header->addLoadCommand(make<LCDylib>(LC_ID_DYLIB, config->installName));
break;
case MH_BUNDLE:
break;
default:
llvm_unreachable("unhandled output file type");
}
Expand Down Expand Up @@ -451,6 +475,7 @@ static int sectionOrder(OutputSection *osec) {
.Default(0);
} else if (segname == segment_names::linkEdit) {
return StringSwitch<int>(osec->name)
.Case(section_names::rebase, -8)
.Case(section_names::binding, -7)
.Case(section_names::weakBinding, -6)
.Case(section_names::lazyBinding, -5)
Expand Down Expand Up @@ -515,6 +540,7 @@ void Writer::createOutputSections() {
make<PageZeroSection>();
break;
case MH_DYLIB:
case MH_BUNDLE:
break;
default:
llvm_unreachable("unhandled output file type");
Expand Down Expand Up @@ -597,6 +623,7 @@ void Writer::run() {
OutputSegment *linkEditSegment =
getOrCreateOutputSegment(segment_names::linkEdit);

prepareBranchTarget(config->entry);
scanRelocations();
if (in.stubHelper->isNeeded())
in.stubHelper->setup();
Expand Down Expand Up @@ -624,6 +651,7 @@ void Writer::run() {
assignAddresses(seg);

// Fill __LINKEDIT contents.
in.rebase->finalizeContents();
in.binding->finalizeContents();
in.weakBinding->finalizeContents();
in.lazyBinding->finalizeContents();
Expand All @@ -649,6 +677,7 @@ void macho::writeResult() { Writer().run(); }

void macho::createSyntheticSections() {
in.header = make<MachHeaderSection>();
in.rebase = make<RebaseSection>();
in.binding = make<BindingSection>();
in.weakBinding = make<WeakBindingSection>();
in.lazyBinding = make<LazyBindingSection>();
Expand Down
24 changes: 24 additions & 0 deletions lld/test/MachO/abs-symbols.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: %lld -lSystem %t.o -o %t
# RUN: llvm-objdump --macho --syms --exports-trie %t | FileCheck %s

# CHECK-LABEL: SYMBOL TABLE:
# CHECK-DAG: 000000000000dead g *ABS* _foo
# CHECK-DAG: 000000000000beef g *ABS* _weakfoo

# CHECK-LABEL: Exports trie:
# CHECK-DAG: 0x0000DEAD _foo [absolute]
# CHECK-DAG: 0x0000BEEF _weakfoo [absolute]

.globl _foo, _weakfoo, _main
.weak_definition _weakfoo
_foo = 0xdead
_weakfoo = 0xbeef

.text
_main:
ret

## TODO: once we support emitting local symbols in the symtab, test local
## absolute symbols too
4 changes: 2 additions & 2 deletions lld/test/MachO/arch.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -o /dev/null %t.o
# RUN: not lld -flavor darwinnew -arch i386 -o /dev/null %t.o 2>&1 | FileCheck %s
# RUN: %lld -o /dev/null %t.o
# RUN: not %lld -arch i386 -o /dev/null %t.o 2>&1 | FileCheck %s
# CHECK: error: missing or unsupported -arch i386

.text
Expand Down
6 changes: 3 additions & 3 deletions lld/test/MachO/archive.s
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

# RUN: rm -f %t/test.a
# RUN: llvm-ar rcs %t/test.a %t/2.o %t/3.o %t/4.o
# RUN: lld -flavor darwinnew %t/main.o %t/test.a -o %t/test.out
# RUN: %lld %t/main.o %t/test.a -o %t/test.out

## TODO: Run llvm-nm -p to validate symbol order
# RUN: llvm-nm %t/test.out | FileCheck %s
Expand All @@ -16,7 +16,7 @@
# CHECK: T _main

## Linking with the archive first in the command line shouldn't change anything
# RUN: lld -flavor darwinnew %t/test.a %t/main.o -o %t/test.out
# RUN: %lld %t/test.a %t/main.o -o %t/test.out
# RUN: llvm-nm %t/test.out | FileCheck %s --check-prefix ARCHIVE-FIRST
# ARCHIVE-FIRST: T _bar
# ARCHIVE-FIRST: T _boo
Expand All @@ -26,7 +26,7 @@
# VISIBLE-NOT: T _undefined
# VISIBLE-NOT: T _unused

# RUN: lld -flavor darwinnew %t/test.a %t/main.o -o %t/all-load -all_load
# RUN: %lld %t/test.a %t/main.o -o %t/all-load -all_load
# RUN: llvm-nm %t/all-load | FileCheck %s --check-prefix ALL-LOAD
# ALL-LOAD: T _bar
# ALL-LOAD: T _boo
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/bss.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -o %t %t.o
# RUN: %lld -o %t %t.o
# RUN: llvm-readobj --section-headers --macho-segment %t | FileCheck %s

## Check that __bss takes up zero file size, is at file offset zero, and
Expand Down
16 changes: 8 additions & 8 deletions lld/test/MachO/common-symbol-coalescing.s
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,26 @@

## Check that we pick the definition with the larger size, regardless of
## its alignment.
# RUN: lld -flavor darwinnew %t/test.o %t/smaller-size.o -order_file %t/order -o %t/test
# RUN: %lld %t/test.o %t/smaller-size.o -order_file %t/order -o %t/test
# RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=SMALLER-ALIGNMENT
# RUN: lld -flavor darwinnew %t/smaller-size.o %t/test.o -order_file %t/order -o %t/test
# RUN: %lld %t/smaller-size.o %t/test.o -order_file %t/order -o %t/test
# RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=SMALLER-ALIGNMENT

## When the sizes are equal, we pick the symbol whose file occurs later in the
## command-line argument list.
# RUN: lld -flavor darwinnew %t/test.o %t/same-size.o -order_file %t/order -o %t/test
# RUN: %lld %t/test.o %t/same-size.o -order_file %t/order -o %t/test
# RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=LARGER-ALIGNMENT
# RUN: lld -flavor darwinnew %t/same-size.o %t/test.o -order_file %t/order -o %t/test
# RUN: %lld %t/same-size.o %t/test.o -order_file %t/order -o %t/test
# RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=SMALLER-ALIGNMENT

# RUN: lld -flavor darwinnew %t/test.o %t/zero-align.o -order_file %t/order -o %t/test
# RUN: %lld %t/test.o %t/zero-align.o -order_file %t/order -o %t/test
# RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=LARGER-ALIGNMENT
# RUN: lld -flavor darwinnew %t/zero-align.o %t/test.o -order_file %t/order -o %t/test
# RUN: %lld %t/zero-align.o %t/test.o -order_file %t/order -o %t/test
# RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=LARGER-ALIGNMENT

# RUN: lld -flavor darwinnew %t/test.o %t/zero-align-round-up.o -order_file %t/order -o %t/test
# RUN: %lld %t/test.o %t/zero-align-round-up.o -order_file %t/order -o %t/test
# RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=LARGER-ALIGNMENT
# RUN: lld -flavor darwinnew %t/zero-align-round-up.o %t/test.o -order_file %t/order -o %t/test
# RUN: %lld %t/zero-align-round-up.o %t/test.o -order_file %t/order -o %t/test
# RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=LARGER-ALIGNMENT

# SMALLER-ALIGNMENT-LABEL: Sections:
Expand Down
26 changes: 13 additions & 13 deletions lld/test/MachO/common-symbol-resolution.s
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/calls-foo.s -o %t/calls-foo.o

# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order -dylib %t/libfoo.o -o %t/libfoo.dylib
# RUN: %lld -lSystem -order_file %t/order -dylib %t/libfoo.o -o %t/libfoo.dylib

# RUN: rm -f %t/defined.a %t/weak-defined-and-common.a
# RUN: llvm-ar rcs %t/defined.a %t/defined.o
Expand All @@ -20,39 +20,39 @@
## regardless of whether it is weak. Moreover, the resolved symbol in the output
## file will always be non-weak, even if the winning input symbol definition was
## weak.
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/common.o %t/weak-common.o %t/test.o -o %t/test
# RUN: %lld -lSystem -order_file %t/order %t/common.o %t/weak-common.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/weak-common.o %t/common.o %t/test.o -o %t/test
# RUN: %lld -lSystem -order_file %t/order %t/weak-common.o %t/common.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON

## Defined symbols are the only ones that take precedence over common symbols.
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/defined.o %t/common.o %t/test.o -o %t/test
# RUN: %lld -lSystem -order_file %t/order %t/defined.o %t/common.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/common.o %t/defined.o %t/test.o -o %t/test
# RUN: %lld -lSystem -order_file %t/order %t/common.o %t/defined.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=DEFINED

# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/weak-defined.o %t/common.o %t/test.o -o %t/test
# RUN: %lld -lSystem -order_file %t/order %t/weak-defined.o %t/common.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/common.o %t/weak-defined.o %t/test.o -o %t/test
# RUN: %lld -lSystem -order_file %t/order %t/common.o %t/weak-defined.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=WEAK-DEFINED

## Common symbols take precedence over archive symbols.
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/defined.a %t/weak-common.o %t/test.o -o %t/test
# RUN: %lld -lSystem -order_file %t/order %t/defined.a %t/weak-common.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/weak-common.o %t/defined.a %t/test.o -o %t/test
# RUN: %lld -lSystem -order_file %t/order %t/weak-common.o %t/defined.a %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON

## If an archive has both a common and a defined symbol, the defined one should
## win.
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/weak-defined-and-common.a %t/calls-foo.o -o %t/calls-foo
# RUN: %lld -lSystem -order_file %t/order %t/weak-defined-and-common.a %t/calls-foo.o -o %t/calls-foo
# RUN: llvm-objdump --syms %t/calls-foo | FileCheck %s --check-prefix=WEAK-DEFINED
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/calls-foo.o %t/weak-defined-and-common.a -o %t/calls-foo
# RUN: %lld -lSystem -order_file %t/order %t/calls-foo.o %t/weak-defined-and-common.a -o %t/calls-foo
# RUN: llvm-objdump --syms %t/calls-foo | FileCheck %s --check-prefix=WEAK-DEFINED

## Common symbols take precedence over dylib symbols.
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/libfoo.dylib %t/weak-common.o %t/test.o -o %t/test
# RUN: %lld -lSystem -order_file %t/order %t/libfoo.dylib %t/weak-common.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem -order_file %t/order %t/weak-common.o %t/libfoo.dylib %t/test.o -o %t/test
# RUN: %lld -lSystem -order_file %t/order %t/weak-common.o %t/libfoo.dylib %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=LARGER-COMMON

# LARGER-COMMON-LABEL: SYMBOL TABLE:
Expand Down
21 changes: 21 additions & 0 deletions lld/test/MachO/compact-unwind-pie.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 %s -o %t.o
# RUN: %lld -pie -lSystem %t.o -o %t
# RUN: llvm-objdump --macho --unwind-info --rebase %t | FileCheck %s

## Check that we do not add rebase opcodes to the compact unwind section.
# CHECK: Contents of __unwind_info section:
# CHECK-NEXT: Version: 0x1
# CHECK-NEXT: Common encodings array section offset:
# CHECK-NEXT: Number of common encodings in array: 0x1
# CHECK: Rebase table:
# CHECK-NEXT: segment section address type
# CHECK-EMPTY:

.globl _main
.text
_main:
.cfi_startproc
.cfi_def_cfa_offset 16
retq
.cfi_endproc
2 changes: 1 addition & 1 deletion lld/test/MachO/compact-unwind.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

# RUN: %python %S/tools/generate-cfi-funcs.py --seed=johnnyapple >%t.s
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin19.0.0 -o %t.o %t.s
# RUN: lld -flavor darwinnew -Z -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem -o %t %t.o
# RUN: %lld -Z -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem -o %t %t.o
# RUN: llvm-objdump --unwind-info --syms %t %t.o >%t.dump
# RUN: %python %S/tools/validate-unwind-info.py %t.dump
4 changes: 2 additions & 2 deletions lld/test/MachO/dso-handle.s
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o

# RUN: lld -flavor darwinnew %t.o -o %t
# RUN: %lld %t.o -o %t
# RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
# CHECK: leaq {{.*}} # 100000000
# CHECK-NEXT: leaq {{.*}} # 100000000

# RUN: lld -flavor darwinnew -dylib %t.o -o %t.dylib
# RUN: %lld -dylib %t.o -o %t.dylib
# RUN: llvm-objdump -d --no-show-raw-insn %t.dylib | FileCheck %s --check-prefix=DYLIB-CHECK
# DYLIB-CHECK: leaq {{.*}} # 0
# DYLIB-CHECK-NEXT: leaq {{.*}} # 0
Expand Down
4 changes: 2 additions & 2 deletions lld/test/MachO/dylib.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o

# RUN: lld -flavor darwinnew -dylib -install_name @executable_path/libfoo.dylib \
# RUN: %lld -dylib -install_name @executable_path/libfoo.dylib \
# RUN: %t.o -o %t.dylib
# RUN: llvm-objdump --macho --dylib-id %t.dylib | FileCheck %s
# CHECK: @executable_path/libfoo.dylib
Expand All @@ -10,7 +10,7 @@
## a flag for a missing entry symbol (since dylibs don't have entry symbols).
## Also check that we come up with the right install name if one isn't
## specified.
# RUN: lld -flavor darwinnew -dylib %t.o -o %t.defaultInstallName.dylib -e missing_entry
# RUN: %lld -dylib %t.o -o %t.defaultInstallName.dylib -e missing_entry
# RUN: obj2yaml %t.defaultInstallName.dylib | FileCheck %s -DOUTPUT=%t.defaultInstallName.dylib --check-prefix=DEFAULT-INSTALL-NAME
# DEFAULT-INSTALL-NAME: [[OUTPUT]]

Expand Down
25 changes: 19 additions & 6 deletions lld/test/MachO/dylink-lazy.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,40 @@
# RUN: -o %t/libhello.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libgoodbye.s \
# RUN: -o %t/libgoodbye.o
# RUN: lld -flavor darwinnew -dylib -L%S/Inputs/MacOSX.sdk/usr/lib \
# RUN: %lld -dylib \
# RUN: -install_name @executable_path/libhello.dylib %t/libhello.o \
# RUN: -o %t/libhello.dylib
# RUN: lld -flavor darwinnew -dylib -L%S/Inputs/MacOSX.sdk/usr/lib \
# RUN: %lld -dylib \
# RUN: -install_name @executable_path/libgoodbye.dylib %t/libgoodbye.o \
# RUN: -o %t/libgoodbye.dylib

# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/dylink-lazy.o
# RUN: lld -flavor darwinnew -o %t/dylink-lazy \
# RUN: -L%S/Inputs/MacOSX.sdk/usr/lib -L%t -lhello -lgoodbye %t/dylink-lazy.o -lSystem
# RUN: %lld -o %t/dylink-lazy \
# RUN: -L%t -lhello -lgoodbye %t/dylink-lazy.o -lSystem

## When looking at the __stubs section alone, we are unable to easily tell which
## symbol each entry points to. So we call objdump twice in order to get the
## disassembly of __text and the bind tables first, which allow us to check for
## matching entries in __stubs.
# RUN: (llvm-objdump -d --no-show-raw-insn --syms --bind --lazy-bind %t/dylink-lazy; \
# RUN: (llvm-objdump -d --no-show-raw-insn --syms --rebase --bind --lazy-bind %t/dylink-lazy; \
# RUN: llvm-objdump -D --no-show-raw-insn %t/dylink-lazy) | FileCheck %s

# RUN: %lld -pie -o %t/dylink-lazy-pie \
# RUN: -L%t -lhello -lgoodbye %t/dylink-lazy.o -lSystem
# RUN: llvm-objdump --macho --rebase %t/dylink-lazy-pie | FileCheck %s --check-prefix=PIE

# CHECK-LABEL: SYMBOL TABLE:
# CHECK: {{0*}}[[#%x, IMGLOADER:]] {{.*}} __DATA,__data __dyld_private

# CHECK-LABEL: Disassembly of section __TEXT,__text:
# CHECK: callq 0x[[#%x, HELLO_STUB:]]
# CHECK-NEXT: callq 0x[[#%x, GOODBYE_STUB:]]

# CHECK-LABEL: Bind table:
## Check that the rebase table is empty.
# CHECK-LABEL: Rebase table:
# CHECK-NEXT: segment section address type

# CHECK-NEXT: Bind table:
# CHECK: __DATA_CONST __got 0x[[#%x, BINDER:]] pointer 0 libSystem dyld_stub_binder

# CHECK-LABEL: Lazy bind table:
Expand All @@ -51,6 +59,11 @@
# CHECK-NEXT: pushq $21
# CHECK-NEXT: jmp 0x[[#STUB_HELPER_ENTRY]]

# PIE: Rebase table:
# PIE-NEXT: segment section address type
# PIE-NEXT: __DATA __la_symbol_ptr 0x[[#%X, ADDR:]] pointer
# PIE-NEXT: __DATA __la_symbol_ptr 0x[[#ADDR + 8]] pointer

.text
.globl _main

Expand Down
6 changes: 3 additions & 3 deletions lld/test/MachO/dylink.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# RUN: -o %t/libhello.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libgoodbye.s \
# RUN: -o %t/libgoodbye.o
# RUN: lld -flavor darwinnew -dylib -install_name \
# RUN: %lld -dylib -install_name \
# RUN: @executable_path/libhello.dylib %t/libhello.o -o %t/libhello.dylib
# RUN: lld -flavor darwinnew -dylib -install_name \
# RUN: %lld -dylib -install_name \
# RUN: @executable_path/libgoodbye.dylib %t/libgoodbye.o -o %t/libgoodbye.dylib

## Make sure we are using the export trie and not the symbol table when linking
Expand All @@ -18,7 +18,7 @@
# NOSYM: no symbols

# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/dylink.o
# RUN: lld -flavor darwinnew -o %t/dylink -Z -L%t -lhello -lgoodbye %t/dylink.o
# RUN: %lld -o %t/dylink -L%t -lhello -lgoodbye %t/dylink.o
# RUN: llvm-objdump --bind -d --no-show-raw-insn %t/dylink | FileCheck %s

# CHECK: movq [[#%u, HELLO_OFF:]](%rip), %rsi
Expand Down
54 changes: 47 additions & 7 deletions lld/test/MachO/entry-symbol.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -o %t %t.o -e _not_main
# RUN: llvm-objdump --macho --all-headers --syms %t | FileCheck %s
# RUN: split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/not-main.s -o %t/not-main.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libfoo.s -o %t/libfoo.o
# RUN: %lld -lSystem -dylib %t/libfoo.o -o %t/libfoo.dylib

# RUN: %lld -o %t/not-main %t/not-main.o -e _not_main
# RUN: llvm-objdump --macho --all-headers --syms %t/not-main | FileCheck %s
# CHECK-LABEL: SYMBOL TABLE
# CHECK-NEXT: {{0*}}[[#%x, ENTRY_ADDR:]] {{.*}} __TEXT,__text _not_main
# CHECK: cmd LC_MAIN
Expand All @@ -15,14 +19,50 @@
# CHECK-NEXT: size
# CHECK-NEXT: offset [[#ENTRYOFF]]

# RUN: %lld -lSystem -o %t/dysym-main %t/not-main.o %t/libfoo.dylib -e _dysym_main
# RUN: llvm-objdump --macho --all-headers --indirect-symbols --lazy-bind %t/dysym-main | FileCheck %s --check-prefix=DYSYM
# DYSYM-LABEL: Indirect symbols for (__TEXT,__stubs) 1 entries
# DYSYM-NEXT: address index name
# DYSYM-NEXT: 0x[[#%x,DYSYM_ENTRY_ADDR:]] [[#]] _dysym_main
# DYSYM-LABEL: cmd LC_MAIN
# DYSYM-NEXT: cmdsize 24
# DYSYM-NEXT: entryoff [[#%u, DYSYM_ENTRY_ADDR - 0x100000000]]
# DYSYM-LABEL: Lazy bind table:
# DYSYM-NEXT: segment section address dylib symbol
# DYSYM-NEXT: __DATA __la_symbol_ptr {{.*}} libfoo _dysym_main

# RUN: %lld -lSystem -o %t/weak-dysym-main %t/not-main.o %t/libfoo.dylib -e _weak_dysym_main
# RUN: llvm-objdump --macho --all-headers --indirect-symbols --bind --weak-bind %t/weak-dysym-main | FileCheck %s --check-prefix=WEAK-DYSYM
# WEAK-DYSYM-LABEL: Indirect symbols for (__TEXT,__stubs) 1 entries
# WEAK-DYSYM-NEXT: address index name
# WEAK-DYSYM-NEXT: 0x[[#%x,DYSYM_ENTRY_ADDR:]] [[#]] _weak_dysym_main
# WEAK-DYSYM: cmd LC_MAIN
# WEAK-DYSYM-NEXT: cmdsize 24
# WEAK-DYSYM-NEXT: entryoff [[#%u, DYSYM_ENTRY_ADDR - 0x100000000]]
# WEAK-DYSYM-LABEL: Bind table:
# WEAK-DYSYM-NEXT: segment section address type addend dylib symbol
# WEAK-DYSYM: __DATA __la_symbol_ptr {{.*}} pointer 0 libfoo _weak_dysym_main
# WEAK-DYSYM-LABEL: Weak bind table:
# WEAK-DYSYM-NEXT: segment section address type addend symbol
# WEAK-DYSYM-NEXT: __DATA __la_symbol_ptr {{.*}} pointer 0 _weak_dysym_main

# RUN: not lld -flavor darwinnew -o /dev/null %t.o -e _missing 2>&1 | FileCheck %s --check-prefix=UNDEFINED
# RUN: not %lld -o /dev/null %t/not-main.o -e _missing 2>&1 | FileCheck %s --check-prefix=UNDEFINED
# UNDEFINED: error: undefined symbol: _missing
# RUN: not lld -flavor darwinnew -o /dev/null %t.o 2>&1 | FileCheck %s --check-prefix=DEFAULT-ENTRY
# RUN: not %lld -o /dev/null %t/not-main.o 2>&1 | FileCheck %s --check-prefix=DEFAULT-ENTRY
# DEFAULT-ENTRY: error: undefined symbol: _main

#--- libfoo.s
.text
.global _dysym_main, _weak_dysym_main
.weak_definition _weak_dysym_main
_dysym_main:
ret

_weak_dysym_main:
ret

#--- not-main.s
.text
.global _not_main
_not_main:
movq $0, %rax
retq
ret
2 changes: 1 addition & 1 deletion lld/test/MachO/export-trie.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## the image base starts at a non-zero address. This allows us to verify that
## addresses in the export trie are correctly encoded as relative to the image
## base.
# RUN: lld -flavor darwinnew %t.o -o %t
# RUN: %lld %t.o -o %t

# RUN: llvm-objdump --syms --exports-trie %t | FileCheck %s --check-prefix=EXPORTS
# EXPORTS-LABEL: SYMBOL TABLE:
Expand Down
4 changes: 2 additions & 2 deletions lld/test/MachO/fat-arch.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# RUN: llvm-mc -filetype=obj -triple=i386-apple-darwin %s -o %t.i386.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.x86_64.o
# RUN: llvm-lipo %t.i386.o %t.x86_64.o -create -o %t.fat.o
# RUN: lld -flavor darwinnew -o /dev/null %t.fat.o
# RUN: %lld -o /dev/null %t.fat.o

# RUN: llvm-lipo %t.i386.o -create -o %t.noarch.o
# RUN: not lld -flavor darwinnew -o /dev/null %t.noarch.o 2>&1 | \
# RUN: not %lld -o /dev/null %t.noarch.o 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.noarch.o
# CHECK: error: unable to find matching architecture in [[FILE]]

Expand Down
12 changes: 6 additions & 6 deletions lld/test/MachO/filelist.s
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,25 @@

# RUN: echo "%t/first.o" > filelist
# RUN: echo "%t/second.o" >> filelist
# RUN: lld -flavor darwinnew -Z -filelist filelist %t/test.o -o %t/test
# RUN: %lld -filelist filelist %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=FIRST

# RUN: echo "%t/second.o" > filelist
# RUN: echo "%t/first.o" >> filelist
# RUN: lld -flavor darwinnew -Z -filelist filelist %t/test.o -o %t/test
# RUN: %lld -filelist filelist %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=SECOND

# RUN: echo "%t/first.o" > filelist
# RUN: lld -flavor darwinnew -Z -filelist filelist %t/second.o %t/test.o -o %t/test
# RUN: %lld -filelist filelist %t/second.o %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=FIRST
# RUN: lld -flavor darwinnew -Z %t/second.o -filelist filelist %t/test.o -o %t/test
# RUN: %lld %t/second.o -filelist filelist %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=SECOND

# RUN: echo "%t/first.o" > filelist-1
# RUN: echo "%t/second.o" > filelist-2
# RUN: lld -flavor darwinnew -Z -filelist filelist-1 -filelist filelist-2 %t/test.o -o %t/test
# RUN: %lld -filelist filelist-1 -filelist filelist-2 %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=FIRST
# RUN: lld -flavor darwinnew -Z -filelist filelist-2 -filelist filelist-1 %t/test.o -o %t/test
# RUN: %lld -filelist filelist-2 -filelist filelist-1 %t/test.o -o %t/test
# RUN: llvm-objdump --syms %t/test | FileCheck %s --check-prefix=SECOND

.globl _main
Expand Down
4 changes: 2 additions & 2 deletions lld/test/MachO/force-load.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
# RUN: echo ".section __TEXT,obj; .globl _foo; .weak_definition _foo; _foo:" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/foo.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o

# RUN: lld -flavor darwinnew -force_load %t/foo.a %t/foo.o %t/test.o -o %t/test-force-load-first
# RUN: %lld -force_load %t/foo.a %t/foo.o %t/test.o -o %t/test-force-load-first
# FORCE-LOAD-FIRST: __TEXT,archive _foo
# RUN: llvm-objdump --syms %t/test-force-load-first | FileCheck %s --check-prefix=FORCE-LOAD-FIRST

# RUN: lld -flavor darwinnew %t/foo.o -force_load %t/foo.a %t/test.o -o %t/test-force-load-second
# RUN: %lld %t/foo.o -force_load %t/foo.a %t/test.o -o %t/test-force-load-second
# RUN: llvm-objdump --syms %t/test-force-load-second | FileCheck %s --check-prefix=FORCE-LOAD-SECOND
# FORCE-LOAD-SECOND: __TEXT,obj _foo

Expand Down
10 changes: 5 additions & 5 deletions lld/test/MachO/framework.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
# RUN: mkdir -p %t
# RUN: echo ".globl _foo; _foo: ret" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/foo.o
# RUN: mkdir -p %t/Foo.framework/Versions/A
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -dylib -install_name %t/Foo.framework/Versions/A/Foo %t/foo.o -o %t/Foo.framework/Versions/A/Foo
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -dylib -install_name %t/Foo.framework/Versions/A/Foobar %t/foo.o -o %t/Foo.framework/Versions/A/Foobar
# RUN: %lld -dylib -install_name %t/Foo.framework/Versions/A/Foo %t/foo.o -o %t/Foo.framework/Versions/A/Foo
# RUN: %lld -dylib -install_name %t/Foo.framework/Versions/A/Foobar %t/foo.o -o %t/Foo.framework/Versions/A/Foobar
# RUN: ln -sf %t/Foo.framework/Versions/A %t/Foo.framework/Versions/Current
# RUN: ln -sf %t/Foo.framework/Versions/Current/Foo %t/Foo.framework/Foo

# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/test.o %s
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem -F%t -framework Foo %t/test.o -o %t/test
# RUN: %lld -lSystem -F%t -framework Foo %t/test.o -o %t/test
# RUN: llvm-objdump --macho --lazy-bind %t/test | FileCheck %s --check-prefix=NOSUFFIX
# NOSUFFIX: __DATA __la_symbol_ptr 0x{{[0-9a-f]*}} {{.*}}Foo _foo

# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem -F%t -framework Foo,baz %t/test.o -o %t/test-wrong-suffix
# RUN: %lld -lSystem -F%t -framework Foo,baz %t/test.o -o %t/test-wrong-suffix
# RUN: llvm-objdump --macho --lazy-bind %t/test-wrong-suffix | FileCheck %s --check-prefix=NOSUFFIX

# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem -F%t -framework Foo,bar %t/test.o -o %t/test-suffix
# RUN: %lld -lSystem -F%t -framework Foo,bar %t/test.o -o %t/test-suffix
# RUN: llvm-objdump --macho --lazy-bind %t/test-suffix | FileCheck %s --check-prefix=SUFFIX
# SUFFIX: __DATA __la_symbol_ptr 0x{{[0-9a-f]*}} {{.*}}Foobar _foo

Expand Down
27 changes: 13 additions & 14 deletions lld/test/MachO/headerpad.s
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

################ Check default behavior
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -o %t %t.o
# RUN: %lld -o %t %t.o
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PADx
#
# PADx: magic {{.+}} ncmds sizeofcmds flags
Expand All @@ -22,9 +22,9 @@
# PADx-NEXT: offset [[#%u, CMDSIZE + 0x20 + 0x20]]

################ Zero pad, no LCDylibs
# RUN: lld -flavor darwinnew -o %t %t.o -headerpad 0
# RUN: %lld -o %t %t.o -headerpad 0
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PAD0
# RUN: lld -flavor darwinnew -o %t %t.o -headerpad 0 -headerpad_max_install_names
# RUN: %lld -o %t %t.o -headerpad 0 -headerpad_max_install_names
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PAD0
#
# PAD0: magic {{.+}} ncmds sizeofcmds flags
Expand All @@ -36,11 +36,11 @@
# PAD0-NEXT: offset [[#%u, CMDSIZE + 0x20 + 0]]

################ Each lexical form of a hex number, no LCDylibs
# RUN: lld -flavor darwinnew -o %t %t.o -headerpad 11
# RUN: %lld -o %t %t.o -headerpad 11
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PAD11
# RUN: lld -flavor darwinnew -o %t %t.o -headerpad 0x11
# RUN: %lld -o %t %t.o -headerpad 0x11
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PAD11
# RUN: lld -flavor darwinnew -o %t %t.o -headerpad 0X11 -headerpad_max_install_names
# RUN: %lld -o %t %t.o -headerpad 0X11 -headerpad_max_install_names
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=PAD11
#
# PAD11: magic {{.+}} ncmds sizeofcmds flags
Expand All @@ -53,16 +53,15 @@

################ Each & all 3 kinds of LCDylib
# RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %T/null.o
# RUN: lld -flavor darwinnew -o %T/libnull.dylib %T/null.o -dylib \
# RUN: %lld -o %T/libnull.dylib %T/null.o -dylib \
# RUN: -headerpad_max_install_names
# RUN: llvm-objdump --macho --all-headers %T/libnull.dylib | FileCheck %s --check-prefix=PADMAX
# RUN: lld -flavor darwinnew -o %T/libnull.dylib %T/null.o -dylib \
# RUN: -headerpad_max_install_names \
# RUN: -syslibroot %S/Inputs/MacOSX.sdk -lSystem
# RUN: %lld -o %T/libnull.dylib %T/null.o -dylib \
# RUN: -headerpad_max_install_names -lSystem
# RUN: llvm-objdump --macho --all-headers %T/libnull.dylib | FileCheck %s --check-prefix=PADMAX
# RUN: lld -flavor darwinnew -o %T/libnull.dylib %T/null.o -dylib \
# RUN: %lld -o %T/libnull.dylib %T/null.o -dylib \
# RUN: -headerpad_max_install_names \
# RUN: -syslibroot %S/Inputs/MacOSX.sdk -lSystem -sub_library libSystem
# RUN: -lSystem -sub_library libSystem
# RUN: llvm-objdump --macho --all-headers %T/libnull.dylib | FileCheck %s --check-prefix=PADMAX
#
# PADMAX: magic {{.+}} ncmds sizeofcmds flags
Expand All @@ -74,9 +73,9 @@
# PADMAX-NEXT: offset [[#%u, CMDSIZE + 0x20 + mul(0x400, N - 6)]]

################ All 3 kinds of LCDylib swamped by a larger override
# RUN: lld -flavor darwinnew -o %T/libnull.dylib %T/null.o -dylib \
# RUN: %lld -o %T/libnull.dylib %T/null.o -dylib \
# RUN: -headerpad_max_install_names -headerpad 0x1001 \
# RUN: -syslibroot %S/Inputs/MacOSX.sdk -lSystem -sub_library libSystem
# RUN: -lSystem -sub_library libSystem
# RUN: llvm-objdump --macho --all-headers %T/libnull.dylib | FileCheck %s --check-prefix=PADOVR
#
# PADOVR: magic {{.+}} ncmds sizeofcmds flags
Expand Down
4 changes: 2 additions & 2 deletions lld/test/MachO/indirect-symtab.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# RUN: split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libfoo.s -o %t/libfoo.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
# RUN: lld -flavor darwinnew -dylib %t/libfoo.o -o %t/libfoo.dylib -syslibroot %S/Inputs/MacOSX.sdk -lSystem
# RUN: lld -flavor darwinnew %t/test.o %t/libfoo.dylib -o %t/test -syslibroot %S/Inputs/MacOSX.sdk -lSystem
# RUN: %lld -dylib %t/libfoo.o -o %t/libfoo.dylib -lSystem
# RUN: %lld %t/test.o %t/libfoo.dylib -o %t/test -lSystem
# RUN: llvm-objdump --macho -d --no-show-raw-insn --indirect-symbols %t/test | FileCheck %s

# CHECK: (__TEXT,__text) section
Expand Down
23 changes: 23 additions & 0 deletions lld/test/MachO/invalid/abs-duplicate.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# REQUIRES: x86
# RUN: split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weakfoo.s -o %t/weakfoo.o
# RUN: not %lld -lSystem %t/test.o %t/weakfoo.o -o %t/test 2>&1 | FileCheck %s

# CHECK: lld: error: duplicate symbol: _weakfoo

#--- weakfoo.s
.globl _weakfoo
## The weak attribute is ignored for absolute symbols, so we will have a
## duplicate symbol error for _weakfoo.
.weak_definition _weakfoo
_weakfoo = 0x1234

#--- test.s
.globl _main, _weakfoo
.weak_definition _weakfoo
_weakfoo = 0x5678

.text
_main:
ret
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/alignment-too-large.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# RUN: yaml2obj %s -o %t.o
# RUN: not lld -flavor darwinnew -o %t %t.o 2>&1 | FileCheck %s
# RUN: not %lld -o %t %t.o 2>&1 | FileCheck %s
#
# CHECK: error: alignment 32 of section __text is too large
--- !mach-o
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/archive-no-index.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# RUN: rm -f %t/test.a
# RUN: llvm-ar rcS %t/test.a %t/2.o %t/3.o %t/4.o

# RUN: not lld -flavor darwinnew %t/test.o %t/test.a -o /dev/null 2>&1 | FileCheck %s
# RUN: not %lld %t/test.o %t/test.a -o /dev/null 2>&1 | FileCheck %s
# CHECK: error: {{.*}}.a: archive has no index; run ranlib to add one

.global _main
Expand Down
4 changes: 2 additions & 2 deletions lld/test/MachO/invalid/bad-archive.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# RUN: echo "foo" >> %t.a
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o

# RUN: not lld -flavor darwinnew %t.o %t.a -o /dev/null 2>&1 | FileCheck -DFILE=%t.a %s
# RUN: not lld -flavor darwinnew %t.o -force_load %t.a -o /dev/null 2>&1 | FileCheck -DFILE=%t.a %s
# RUN: not %lld %t.o %t.a -o /dev/null 2>&1 | FileCheck -DFILE=%t.a %s
# RUN: not %lld %t.o -force_load %t.a -o /dev/null 2>&1 | FileCheck -DFILE=%t.a %s
# CHECK: error: [[FILE]]: failed to parse archive: truncated or malformed archive (remaining size of archive too small for next archive member header at offset 8)

.global _main
Expand Down
6 changes: 3 additions & 3 deletions lld/test/MachO/invalid/bad-got-to-dylib-tlv-reference.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# RUN: split-file %s %t

# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libtlv.s -o %t/libtlv.o
# RUN: lld -flavor darwinnew -dylib -install_name @executable_path/libtlv.dylib \
# RUN: -Z -L%S/../Inputs/MacOSX.sdk/usr/lib -lSystem -o %t/libtlv.dylib %t/libtlv.o
# RUN: %lld -dylib -install_name @executable_path/libtlv.dylib \
# RUN: -lSystem -o %t/libtlv.dylib %t/libtlv.o

# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
# RUN: not lld -flavor darwinnew -Z -L%S/../Inputs/MacOSX.sdk/usr/lib -lSystem -L%t -ltlv -o /dev/null %t/test.o 2>&1 | FileCheck %s -DFILE=%t/test.o
# RUN: not %lld -lSystem -L%t -ltlv -o /dev/null %t/test.o 2>&1 | FileCheck %s -DFILE=%t/test.o

# CHECK: error: found GOT relocation referencing thread-local variable in [[FILE]]:(__text)

Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/bad-got-to-tlv-reference.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: not lld -flavor darwinnew -o /dev/null %t.o 2>&1 | FileCheck %s -DFILE=%t.o
# RUN: not %lld -o /dev/null %t.o 2>&1 | FileCheck %s -DFILE=%t.o

# CHECK: error: found GOT relocation referencing thread-local variable in [[FILE]]:(__text)

Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/bad-tlv-def.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: not lld -flavor darwinnew -o /dev/null %t.o 2>&1 | FileCheck %s
# RUN: not %lld -o /dev/null %t.o 2>&1 | FileCheck %s

# CHECK: error: relocations in thread-local variable sections must be X86_64_RELOC_UNSIGNED

Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/bad-tlv-opcode.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: not lld -flavor darwinnew -o /dev/null %t.o 2>&1 | FileCheck %s
# RUN: not %lld -o /dev/null %t.o 2>&1 | FileCheck %s

# CHECK: error: X86_64_RELOC_TLV must be used with movq instructions

Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/bad-tlv-relocation.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: not lld -flavor darwinnew -o /dev/null %t.o 2>&1 | FileCheck %s -DFILE=%t.o
# RUN: not %lld -o /dev/null %t.o 2>&1 | FileCheck %s -DFILE=%t.o

# CHECK: error: found X86_64_RELOC_TLV referencing a non-thread-local variable in [[FILE]]:(__text)

Expand Down
4 changes: 2 additions & 2 deletions lld/test/MachO/invalid/dso-handle-duplicate.s
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
## far-out edge case that should be safe to ignore.

# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: not lld -flavor darwinnew -dylib %t.o -o %t.dylib 2>&1 | FileCheck %s -DFILE=%t.o
# CHECK: error: found defined symbol from [[FILE]] with illegal name ___dso_handle
# RUN: not %lld -dylib %t.o -o %t.dylib 2>&1 | FileCheck %s
# CHECK: error: found defined symbol with illegal name ___dso_handle

.globl _main, ___dso_handle
.text
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/duplicate-symbol.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t-dup.o
# RUN: not lld -flavor darwinnew -o /dev/null %t-dup.o %t.o 2>&1 | FileCheck %s
# RUN: not %lld -o /dev/null %t-dup.o %t.o 2>&1 | FileCheck %s

# CHECK: error: duplicate symbol: _main

Expand Down
4 changes: 2 additions & 2 deletions lld/test/MachO/invalid/invalid-executable.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -o %t %t.o
# RUN: not lld -flavor darwinnew -o /dev/null %t 2>&1 | FileCheck %s -DFILE=%t
# RUN: %lld -o %t %t.o
# RUN: not %lld -o /dev/null %t 2>&1 | FileCheck %s -DFILE=%t
# CHECK: error: [[FILE]]: unhandled file type

.text
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/invalid-fat-narch.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: yaml2obj %s -o %t.o
# RUN: not lld -flavor darwinnew -o /dev/null %t.o 2>&1 | \
# RUN: not %lld -o /dev/null %t.o 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.o
# CHECK: error: [[FILE]]: fat_arch struct extends beyond end of file

Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/invalid-fat-offset.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: yaml2obj %s -o %t.o
# RUN: not lld -flavor darwinnew -o /dev/null %t.o 2>&1 | \
# RUN: not %lld -o /dev/null %t.o 2>&1 | \
# RUN: FileCheck %s -DFILE=%t.o
# CHECK: error: [[FILE]]: slice extends beyond end of file

Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/invalid-relocation-length.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: yaml2obj %s -o %t.o
# RUN: not lld -flavor darwinnew -o %t %t.o 2>&1 | FileCheck %s -DFILE=%t.o
# RUN: not %lld -o %t %t.o 2>&1 | FileCheck %s -DFILE=%t.o
#
# CHECK: error: invalid relocation at offset 1 of __TEXT,__text in [[FILE]]: relocations of type 0 must have r_length of 2 or 3

Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/invalid-relocation-pcrel.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: yaml2obj %s -o %t.o
# RUN: not lld -flavor darwinnew -o %t %t.o 2>&1 | FileCheck %s -DFILE=%t.o
# RUN: not %lld -o %t %t.o 2>&1 | FileCheck %s -DFILE=%t.o
#
# CHECK: error: invalid relocation at offset 1 of __TEXT,__text in [[FILE]]: relocations of type 0 must not be pcrel

Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/invalid-stub.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# RUN: echo "--- !tapi-tbd-v3" > %t/libinvalidYAML.tbd
# RUN: echo "invalid YAML" >> %t/libinvalidYAML.tbd
# RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %s -o %t/test.o
# RUN: not lld -flavor darwinnew -Z -L%t -linvalidYAML %t/test.o -o %t/test -Z 2>&1 | FileCheck %s -DDIR=%t
# RUN: not %lld -L%t -linvalidYAML %t/test.o -o %t/test 2>&1 | FileCheck %s -DDIR=%t

# CHECK: could not load TAPI file at [[DIR]]{{[\\/]}}libinvalidYAML.tbd: malformed file

Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/missing-dylib.s
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: not lld -flavor darwinnew -Z -o %t -lmissing %t.o 2>&1 | FileCheck %s
# RUN: not %lld -o %t -lmissing %t.o 2>&1 | FileCheck %s

# CHECK: error: library not found for -lmissing
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/no-filelist.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: not lld -flavor darwinnew -Z -filelist nonexistent %t.o -o %t 2>&1 | FileCheck %s
# RUN: not %lld -filelist nonexistent %t.o -o %t 2>&1 | FileCheck %s
# CHECK: cannot open nonexistent: {{N|n}}o such file or directory

.globl _main
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/no-id-dylink.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# RUN: mkdir -p %t
# RUN: yaml2obj %s -o %t/libnoid.dylib
# RUN: echo ".globl _main; .text; _main: ret" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/no-id-dylink.o
# RUN: not lld -flavor darwinnew -o %t/no-id-dylink -Z -L%t -lnoid %t/no-id-dylink.o 2>&1 | FileCheck %s
# RUN: not %lld -o %t/no-id-dylink -L%t -lnoid %t/no-id-dylink.o 2>&1 | FileCheck %s
# CHECK: error: dylib {{.*}}libnoid.dylib missing LC_ID_DYLIB load command

## This YAML file was originally generated from linking the following source
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/no-such-file.s
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# REQUIRES: x86
# RUN: not lld -flavor darwinnew -o /dev/null %t-no-such-file.o 2>&1 | FileCheck %s
# RUN: not %lld -o /dev/null %t-no-such-file.o 2>&1 | FileCheck %s

# CHECK: error: cannot open {{.*}}no-such-file.o
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/order-file-bad-arch.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: echo ".globl _main; .text; _main: ret" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t.o
# RUN: not lld -flavor darwinnew -o %t %t.o -order_file %s 2>&1 | FileCheck %s
# RUN: not %lld -o %t %t.o -order_file %s 2>&1 | FileCheck %s
# CHECK: error: invalid arch "sparc" in order file: expected one of arm, arm64, i386, x86_64, ppc, ppc64
# CHECK-EMPTY:

Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/order-file-bad-objfile.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: echo ".globl _main; .text; _main: ret" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t.o
# RUN: not lld -flavor darwinnew -o %t %t.o -order_file %s 2>&1 | FileCheck %s
# RUN: not %lld -o %t %t.o -order_file %s 2>&1 | FileCheck %s
# CHECK: invalid object file name "helloo" in order file: should end with .o
# CHECK: invalid object file name "z80" in order file: should end with .o
# CHECK-EMPTY:
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/reserved-section-name.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: not lld -flavor darwinnew -o %t %t.o 2>&1 | FileCheck %s -DFILE=%t.o
# RUN: not %lld -o %t %t.o 2>&1 | FileCheck %s -DFILE=%t.o
# CHECK: error: section from [[FILE]] conflicts with synthetic section __DATA_CONST,__got

.globl _main
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/stub-link.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# RUN: mkdir -p %t
#
# RUN: llvm-mc -filetype obj -triple x86_64-apple-ios %s -o %t/test.o
# RUN: not lld -flavor darwinnew -o %t/test -Z -L%S/../Inputs/iPhoneSimulator.sdk/usr/lib -lSystem %t/test.o 2>&1 | FileCheck %s
# RUN: not lld -flavor darwinnew -o %t/test -syslibroot %S/../Inputs/iPhoneSimulator.sdk -lSystem %t/test.o 2>&1 | FileCheck %s

# CHECK-DAG: error: undefined symbol __cache_handle_memory_pressure_event
# CHECK-DAG: error: undefined symbol _from_non_reexported_tapi_dylib
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/invalid/undefined-symbol.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: not lld -flavor darwinnew -Z -o %t %t.o 2>&1 | FileCheck %s -DBASENAME=%basename_t
# RUN: not %lld -o %t %t.o 2>&1 | FileCheck %s -DBASENAME=%basename_t
# CHECK: error: undefined symbol _foo, referenced from [[BASENAME]]

.globl _main
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/lc-build-version.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -Z -platform_version macos 10.14.1 10.15 -o %t %t.o
# RUN: %lld -platform_version macos 10.14.1 10.15 -o %t %t.o
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s

# CHECK: cmd LC_BUILD_VERSION
Expand Down
22 changes: 11 additions & 11 deletions lld/test/MachO/link-search-order.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,44 @@
# RUN: mkdir -p %t %tA %tD
#
# RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %p/Inputs/libhello.s -o %t/hello.o
# RUN: lld -flavor darwinnew -dylib -install_name @executable_path/libhello.dylib %t/hello.o -o %t/libhello.dylib
# RUN: %lld -dylib -install_name @executable_path/libhello.dylib %t/hello.o -o %t/libhello.dylib
#
# RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %p/Inputs/libgoodbye.s -o %t/goodbye.o
# RUN: lld -flavor darwinnew -dylib -install_name @executable_path/libgoodbye.dylib %t/goodbye.o -o %tD/libgoodbye.dylib
# RUN: %lld -dylib -install_name @executable_path/libgoodbye.dylib %t/goodbye.o -o %tD/libgoodbye.dylib
# RUN: llvm-ar --format=darwin crs %tA/libgoodbye.a %t/goodbye.o
#
# RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %s -o %t/test.o

################ default, which is the same as -search_paths_first
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: %lld -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: -L%tA -L%tD -L%t -lhello -lgoodbye -lSystem %t/test.o
# RUN: llvm-objdump --macho --dylibs-used %t/test | FileCheck --check-prefix=ARCHIVE %s

################ Test all permutations of -L%t{A,D} with -search_paths_first
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: %lld -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: -L%tA -L%tD -L%t -lhello -lgoodbye -lSystem %t/test.o -search_paths_first
# RUN: llvm-objdump --macho --dylibs-used %t/test | FileCheck --check-prefix=ARCHIVE %s
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: %lld -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: -L%tD -L%tA -L%t -lhello -lgoodbye -lSystem %t/test.o -search_paths_first
# RUN: llvm-objdump --macho --dylibs-used %t/test | FileCheck --check-prefix=DYLIB %s
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: %lld -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: -L%tA -L%t -lhello -lgoodbye -lSystem %t/test.o -search_paths_first
# RUN: llvm-objdump --macho --dylibs-used %t/test | FileCheck --check-prefix=ARCHIVE %s
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: %lld -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: -L%tD -L%t -lhello -lgoodbye -lSystem %t/test.o -search_paths_first
# RUN: llvm-objdump --macho --dylibs-used %t/test | FileCheck --check-prefix=DYLIB %s

################ Test all permutations of -L%t{A,D} with -search_dylibs_first
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: %lld -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: -L%tA -L%tD -L%t -lhello -lgoodbye -lSystem %t/test.o -search_dylibs_first
# RUN: llvm-objdump --macho --dylibs-used %t/test | FileCheck --check-prefix=DYLIB %s
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: %lld -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: -L%tD -L%tA -L%t -lhello -lgoodbye -lSystem %t/test.o -search_dylibs_first
# RUN: llvm-objdump --macho --dylibs-used %t/test | FileCheck --check-prefix=DYLIB %s
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: %lld -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: -L%tA -L%t -lhello -lgoodbye -lSystem %t/test.o -search_dylibs_first
# RUN: llvm-objdump --macho --dylibs-used %t/test | FileCheck --check-prefix=ARCHIVE %s
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: %lld -L%S/Inputs/MacOSX.sdk/usr/lib -o %t/test -Z \
# RUN: -L%tD -L%t -lhello -lgoodbye -lSystem %t/test.o -search_dylibs_first
# RUN: llvm-objdump --macho --dylibs-used %t/test | FileCheck --check-prefix=DYLIB %s

Expand Down
6 changes: 3 additions & 3 deletions lld/test/MachO/linkedit-contiguity.s
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@

# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libhello.s \
# RUN: -o %t/libhello.o
# RUN: lld -flavor darwinnew -dylib -L%S/Inputs/MacOSX.sdk/usr/lib \
# RUN: %lld -dylib \
# RUN: -install_name @executable_path/libhello.dylib %t/libhello.o \
# RUN: -o %t/libhello.dylib

# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o
# RUN: lld -flavor darwinnew -o %t/test \
# RUN: -L%S/Inputs/MacOSX.sdk/usr/lib -L%t -lhello %t/test.o -lSystem
# RUN: %lld -o %t/test \
# RUN: -L%t -lhello %t/test.o -lSystem

# RUN: llvm-objdump --macho --all-headers %t/test | FileCheck %s

Expand Down
6 changes: 6 additions & 0 deletions lld/test/MachO/lit.local.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# -*- Python -*-

import os

config.substitutions.append(('%lld', 'lld -flavor darwinnew -syslibroot ' +
os.path.join(config.test_source_root, "MachO", "Inputs", "MacOSX.sdk")))
51 changes: 40 additions & 11 deletions lld/test/MachO/load-commands.s
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -o %t %t.o
# RUN: rm -rf %t && mkdir -p %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o
# RUN: %lld -o %t/executable %t/test.o
# RUN: %lld -bundle -o %t/bundle %t/test.o
# RUN: %lld -dylib -o %t/dylib %t/test.o

## These load commands should be in every final output binary.
# COMMON-DAG: cmd LC_DYLD_INFO_ONLY
# COMMON-DAG: cmd LC_SYMTAB
# COMMON-DAG: cmd LC_DYSYMTAB

## Check for the presence of load commands that are essential for a working
## executable.
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s
# CHECK-DAG: cmd LC_DYLD_INFO_ONLY
# CHECK-DAG: cmd LC_SYMTAB
# CHECK-DAG: cmd LC_DYSYMTAB
# CHECK-DAG: cmd LC_MAIN
# CHECK-DAG: cmd LC_LOAD_DYLINKER
## executable. Also check that it has the right filetype.
# RUN: llvm-objdump --macho --all-headers %t/executable | FileCheck %s --check-prefix=COMMON
# RUN: llvm-objdump --macho --all-headers %t/executable | FileCheck %s --check-prefix=EXEC
# EXEC: magic cputype cpusubtype caps filetype
# EXEC-NEXT: MH_MAGIC_64 X86_64 ALL {{.*}} EXECUTE
# EXEC-DAG: cmd LC_MAIN
# EXEC-DAG: cmd LC_LOAD_DYLINKER

## Check for the absence of load commands that should not be in an executable.
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s --check-prefix=NCHECK
# NCHECK-NOT: cmd: LC_ID_DYLIB
# RUN: llvm-objdump --macho --all-headers %t/executable | FileCheck %s --check-prefix=NEXEC
# NEXEC-NOT: cmd: LC_ID_DYLIB

## Check for the presence / absence of load commands for the dylib.
# RUN: llvm-objdump --macho --all-headers %t/dylib | FileCheck %s --check-prefix=COMMON
# RUN: llvm-objdump --macho --all-headers %t/dylib | FileCheck %s --check-prefix=DYLIB
# DYLIB: magic cputype cpusubtype caps filetype
# DYLIB-NEXT: MH_MAGIC_64 X86_64 ALL {{.*}} DYLIB
# DYLIB: cmd LC_ID_DYLIB

# RUN: llvm-objdump --macho --all-headers %t/bundle | FileCheck %s --check-prefix=NDYLIB
# NDYLIB-NOT: cmd: LC_MAIN
# NDYLIB-NOT: cmd: LC_LOAD_DYLINKER

## Check for the presence / absence of load commands for the bundle.
# RUN: llvm-objdump --macho --all-headers %t/bundle | FileCheck %s --check-prefix=COMMON
# RUN: llvm-objdump --macho --all-headers %t/bundle | FileCheck %s --check-prefix=BUNDLE
# BUNDLE: magic cputype cpusubtype caps filetype
# BUNDLE-NEXT: MH_MAGIC_64 X86_64 ALL {{.*}} BUNDLE

# RUN: llvm-objdump --macho --all-headers %t/bundle | FileCheck %s --check-prefix=NBUNDLE
# NBUNDLE-NOT: cmd: LC_MAIN
# NBUNDLE-NOT: cmd: LC_LOAD_DYLINKER

.text
.global _main
Expand Down
23 changes: 19 additions & 4 deletions lld/test/MachO/local-got.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# RUN: mkdir -p %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libhello.s \
# RUN: -o %t/libhello.o
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem -dylib -install_name \
# RUN: %lld -lSystem -dylib -install_name \
# RUN: @executable_path/libhello.dylib %t/libhello.o -o %t/libhello.dylib
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem -o %t/test %t/test.o -L%t -lhello
# RUN: llvm-objdump --full-contents --bind %t/test | FileCheck %s --match-full-lines
# RUN: %lld -lSystem -o %t/test %t/test.o -L%t -lhello
# RUN: llvm-objdump --full-contents --rebase --bind %t/test | FileCheck %s --match-full-lines

## Check that the GOT references the cstrings. --full-contents displays the
## address offset and the contents at that address very similarly, so am using
Expand All @@ -20,11 +20,26 @@
# CHECK-NEXT: [[#%X,ADDR:]] 1a040000 01000000 0c040000 01000000 {{.*}}
# CHECK-NEXT: [[#ADDR + 16]] 00000000 00000000 {{.*}}

## Check that the rebase table is empty.
# CHECK: Rebase table:
# CHECK-NEXT: segment section address type

## Check that a non-locally-defined symbol is still bound at the correct offset:
# CHECK: Bind table:
# CHECK-NEXT: Bind table:
# CHECK-NEXT: segment section address type addend dylib symbol
# CHECK-NEXT: __DATA_CONST __got 0x[[#ADDR+16]] pointer 0 libhello _hello_its_me

# RUN: %lld -pie -lSystem -o %t/test %t/test.o -L%t -lhello
# RUN: llvm-objdump --macho --rebase --bind %t/test | FileCheck %s --check-prefix=PIE --match-full-lines
# PIE: Rebase table:
# PIE-NEXT: segment section address type
# PIE-NEXT: __DATA_CONST __got 0x[[#%X,ADDR:]] pointer
# PIE-NEXT: __DATA_CONST __got 0x[[#ADDR + 8]] pointer

# PIE-NEXT: Bind table:
# PIE-NEXT: segment section address type addend dylib symbol
# PIE-NEXT: __DATA_CONST __got 0x[[#ADDR+16]] pointer 0 libhello _hello_its_me

.globl _main

.text
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/no-exports-dylib.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -dylib %t.o -o %t.dylib
# RUN: %lld -dylib %t.o -o %t.dylib

# RUN: obj2yaml %t.dylib | FileCheck %s
# CHECK: export_size: 0
2 changes: 1 addition & 1 deletion lld/test/MachO/no-unneeded-dyld-info.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -o %t %t.o
# RUN: %lld -o %t %t.o
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s

# CHECK: cmd LC_DYLD_INFO_ONLY
Expand Down
12 changes: 6 additions & 6 deletions lld/test/MachO/nonweak-definition-override.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/nonweakdef.s -o %t/nonweakdef.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/weakdef.s -o %t/weakdef.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/common.s -o %t/common.o
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -dylib %t/libfoo.o -o %t/libfoo.dylib
# RUN: %lld -dylib %t/libfoo.o -o %t/libfoo.dylib

## Check that non-weak defined symbols override weak dylib symbols.
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk %t/nonweakdef.o -L%t -lfoo -o %t/nonweakdef -lSystem
# RUN: %lld %t/nonweakdef.o -L%t -lfoo -o %t/nonweakdef -lSystem
# RUN: llvm-objdump --macho --weak-bind %t/nonweakdef | FileCheck %s

## Test loading the dylib before the obj file.
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -L%t -lfoo %t/nonweakdef.o -o %t/nonweakdef -lSystem
# RUN: %lld -L%t -lfoo %t/nonweakdef.o -o %t/nonweakdef -lSystem
# RUN: llvm-objdump --macho --weak-bind %t/nonweakdef | FileCheck %s

# CHECK: Weak bind table:
Expand All @@ -20,11 +20,11 @@
# CHECK-EMPTY:

## Check that weak defined symbols do not override weak dylib symbols.
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk %t/weakdef.o -L%t -lfoo -o %t/weakdef -lSystem
# RUN: %lld %t/weakdef.o -L%t -lfoo -o %t/weakdef -lSystem
# RUN: llvm-objdump --macho --weak-bind %t/weakdef | FileCheck %s --check-prefix=NO-WEAK-OVERRIDE

## Test loading the dylib before the obj file.
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -L%t -lfoo %t/weakdef.o -o %t/weakdef -lSystem
# RUN: %lld -L%t -lfoo %t/weakdef.o -o %t/weakdef -lSystem
# RUN: llvm-objdump --macho --weak-bind %t/weakdef | FileCheck %s --check-prefix=NO-WEAK-OVERRIDE

# NO-WEAK-OVERRIDE: Weak bind table:
Expand All @@ -33,7 +33,7 @@

## Check that common symbols take precedence over weak dylib symbols, but do not
## generate an overridding weak binding.
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -L%t -lfoo %t/common.o -o %t/common -lSystem
# RUN: %lld -L%t -lfoo %t/common.o -o %t/common -lSystem
# RUN: llvm-objdump --macho --weak-bind %t/common | FileCheck %s --check-prefix=NO-WEAK-OVERRIDE
# RUN: llvm-objdump --syms %t/common | FileCheck %s --check-prefix=COMMON
# COMMON-DAG: g O __DATA,__common _nonweak_in_dylib
Expand Down
4 changes: 2 additions & 2 deletions lld/test/MachO/objc.s
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# RUN: llvm-ar rcs %t/libHasSomeObjC.a %t/has-objc-symbol.o %t/has-objc-category.o %t/has-swift.o %t/no-objc.o

# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem %t/test.o -o %t/test \
# RUN: %lld -lSystem %t/test.o -o %t/test \
# RUN: -L%t -lHasSomeObjC -ObjC
# RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=OBJC

Expand All @@ -24,7 +24,7 @@
# OBJC-NEXT: g F __TEXT,__text _main
# OBJC-NEXT: g F __TEXT,__text _OBJC_CLASS_$_MyObject

# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -lSystem %t/test.o -o %t/test \
# RUN: %lld -lSystem %t/test.o -o %t/test \
# RUN: -L%t -lHasSomeObjC
# RUN: llvm-objdump --section-headers --syms %t/test | FileCheck %s --check-prefix=NO-OBJC

Expand Down
56 changes: 28 additions & 28 deletions lld/test/MachO/order-file.s
Original file line number Diff line number Diff line change
Expand Up @@ -14,67 +14,67 @@

# RUN: echo "_foo # just a comment" > %t/ord-1
# RUN: echo "_main # another comment" >> %t/ord-1
# RUN: lld -flavor darwinnew -o %t/test-1 %t/test.o %t/foo.o -order_file %t/ord-1
# RUN: %lld -o %t/test-1 %t/test.o %t/foo.o -order_file %t/ord-1
# RUN: llvm-objdump -d %t/test-1 | FileCheck %s --check-prefix=FOO-FIRST
## Output should be the same regardless of the command-line order of object files
# RUN: lld -flavor darwinnew -o %t/test-1 %t/foo.o %t/test.o -order_file %t/ord-1
# RUN: %lld -o %t/test-1 %t/foo.o %t/test.o -order_file %t/ord-1
# RUN: llvm-objdump -d %t/test-1 | FileCheck %s --check-prefix=FOO-FIRST

# RUN: echo "_main # just a comment" > %t/ord-2
# RUN: echo "_foo # another comment" >> %t/ord-2
# RUN: lld -flavor darwinnew -o %t/test-2 %t/test.o %t/foo.o -order_file %t/ord-2
# RUN: %lld -o %t/test-2 %t/test.o %t/foo.o -order_file %t/ord-2
# RUN: llvm-objdump -d %t/test-2 | FileCheck %s --check-prefix=FOO-SECOND
# RUN: lld -flavor darwinnew -o %t/test-2 %t/foo.o %t/test.o -order_file %t/ord-2
# RUN: %lld -o %t/test-2 %t/foo.o %t/test.o -order_file %t/ord-2
# RUN: llvm-objdump -d %t/test-2 | FileCheck %s --check-prefix=FOO-SECOND

# RUN: echo "foo.o:_foo" > %t/ord-file-match
# RUN: echo "_main" >> %t/ord-file-match
# RUN: lld -flavor darwinnew -o %t/test-file-match %t/test.o %t/foo.o -order_file %t/ord-file-match
# RUN: %lld -o %t/test-file-match %t/test.o %t/foo.o -order_file %t/ord-file-match
# RUN: llvm-objdump -d %t/test-file-match | FileCheck %s --check-prefix=FOO-FIRST
## Output should be the same regardless of the command-line order of object files
# RUN: lld -flavor darwinnew -o %t/test-file-match %t/foo.o %t/test.o -order_file %t/ord-file-match
# RUN: %lld -o %t/test-file-match %t/foo.o %t/test.o -order_file %t/ord-file-match
# RUN: llvm-objdump -d %t/test-file-match | FileCheck %s --check-prefix=FOO-FIRST

# RUN: echo "bar.o:_foo" > %t/ord-file-nomatch
# RUN: echo "_main" >> %t/ord-file-nomatch
# RUN: echo "_foo" >> %t/ord-file-nomatch
# RUN: lld -flavor darwinnew -o %t/test-file-nomatch %t/test.o %t/foo.o -order_file %t/ord-file-nomatch
# RUN: %lld -o %t/test-file-nomatch %t/test.o %t/foo.o -order_file %t/ord-file-nomatch
# RUN: llvm-objdump -d %t/test-file-nomatch | FileCheck %s --check-prefix=FOO-SECOND
# RUN: lld -flavor darwinnew -o %t/test-file-nomatch %t/foo.o %t/test.o -order_file %t/ord-file-nomatch
# RUN: %lld -o %t/test-file-nomatch %t/foo.o %t/test.o -order_file %t/ord-file-nomatch
# RUN: llvm-objdump -d %t/test-file-nomatch | FileCheck %s --check-prefix=FOO-SECOND

# RUN: echo "x86_64:_foo" > %t/ord-arch-match
# RUN: echo "_main" >> %t/ord-arch-match
# RUN: lld -flavor darwinnew -o %t/test-arch-match %t/test.o %t/foo.o -order_file %t/ord-arch-match
# RUN: %lld -o %t/test-arch-match %t/test.o %t/foo.o -order_file %t/ord-arch-match
# RUN: llvm-objdump -d %t/test-arch-match | FileCheck %s --check-prefix=FOO-FIRST
# RUN: lld -flavor darwinnew -o %t/test-arch-match %t/foo.o %t/test.o -order_file %t/ord-arch-match
# RUN: %lld -o %t/test-arch-match %t/foo.o %t/test.o -order_file %t/ord-arch-match
# RUN: llvm-objdump -d %t/test-arch-match | FileCheck %s --check-prefix=FOO-FIRST

# RUN: echo "ppc:_foo" > %t/ord-arch-nomatch
# RUN: echo "_main" >> %t/ord-arch-nomatch
# RUN: echo "_foo" >> %t/ord-arch-nomatch
# RUN: lld -flavor darwinnew -o %t/test-arch-nomatch %t/test.o %t/foo.o -order_file %t/ord-arch-nomatch
# RUN: %lld -o %t/test-arch-nomatch %t/test.o %t/foo.o -order_file %t/ord-arch-nomatch
# RUN: llvm-objdump -d %t/test-arch-nomatch | FileCheck %s --check-prefix=FOO-SECOND
# RUN: lld -flavor darwinnew -o %t/test-arch-nomatch %t/foo.o %t/test.o -order_file %t/ord-arch-nomatch
# RUN: %lld -o %t/test-arch-nomatch %t/foo.o %t/test.o -order_file %t/ord-arch-nomatch
# RUN: llvm-objdump -d %t/test-arch-nomatch | FileCheck %s --check-prefix=FOO-SECOND

# RUN: echo "x86_64:bar.o:_foo" > %t/ord-arch-file-match
# RUN: echo "_main" >> %t/ord-arch-match
# RUN: lld -flavor darwinnew -o %t/test-arch-match %t/test.o %t/foo.o -order_file %t/ord-arch-match
# RUN: %lld -o %t/test-arch-match %t/test.o %t/foo.o -order_file %t/ord-arch-match
# RUN: llvm-objdump -d %t/test-arch-match | FileCheck %s --check-prefix=FOO-FIRST
# RUN: lld -flavor darwinnew -o %t/test-arch-match %t/foo.o %t/test.o -order_file %t/ord-arch-match
# RUN: %lld -o %t/test-arch-match %t/foo.o %t/test.o -order_file %t/ord-arch-match
# RUN: llvm-objdump -d %t/test-arch-match | FileCheck %s --check-prefix=FOO-FIRST

## Test archives

# RUN: lld -flavor darwinnew -o %t/test-archive-1 %t/test.o %t/foo.a -order_file %t/ord-1
# RUN: %lld -o %t/test-archive-1 %t/test.o %t/foo.a -order_file %t/ord-1
# RUN: llvm-objdump -d %t/test-archive-1 | FileCheck %s --check-prefix=FOO-FIRST
# RUN: lld -flavor darwinnew -o %t/test-archive-1 %t/foo.a %t/test.o -order_file %t/ord-1
# RUN: %lld -o %t/test-archive-1 %t/foo.a %t/test.o -order_file %t/ord-1
# RUN: llvm-objdump -d %t/test-archive-1 | FileCheck %s --check-prefix=FOO-FIRST

# RUN: lld -flavor darwinnew -o %t/test-archive-file-no-match %t/test.o %t/foo.a -order_file %t/ord-file-nomatch
# RUN: %lld -o %t/test-archive-file-no-match %t/test.o %t/foo.a -order_file %t/ord-file-nomatch
# RUN: llvm-objdump -d %t/test-archive-file-no-match | FileCheck %s --check-prefix=FOO-SECOND
# RUN: lld -flavor darwinnew -o %t/test-archive %t/foo.a %t/test.o -order_file %t/ord-file-nomatch
# RUN: %lld -o %t/test-archive %t/foo.a %t/test.o -order_file %t/ord-file-nomatch
# RUN: llvm-objdump -d %t/test-archive-file-no-match | FileCheck %s --check-prefix=FOO-SECOND

## The following tests check that if an address is matched by multiple order
Expand All @@ -83,33 +83,33 @@
# RUN: echo "_foo" > %t/ord-multiple-1
# RUN: echo "_main" >> %t/ord-multiple-1
# RUN: echo "foo.o:_foo" >> %t/ord-multiple-1
# RUN: lld -flavor darwinnew -o %t/test-1 %t/test.o %t/foo.o -order_file %t/ord-multiple-1
# RUN: %lld -o %t/test-1 %t/test.o %t/foo.o -order_file %t/ord-multiple-1
# RUN: llvm-objdump -d %t/test-1 | FileCheck %s --check-prefix=FOO-FIRST
# RUN: lld -flavor darwinnew -o %t/test-1 %t/foo.o %t/test.o -order_file %t/ord-multiple-1
# RUN: %lld -o %t/test-1 %t/foo.o %t/test.o -order_file %t/ord-multiple-1
# RUN: llvm-objdump -d %t/test-1 | FileCheck %s --check-prefix=FOO-FIRST

# RUN: echo "foo.o:_foo" > %t/ord-multiple-2
# RUN: echo "_main" >> %t/ord-multiple-2
# RUN: echo "_foo" >> %t/ord-multiple-2
# RUN: lld -flavor darwinnew -o %t/test-2 %t/test.o %t/foo.o -order_file %t/ord-multiple-2
# RUN: %lld -o %t/test-2 %t/test.o %t/foo.o -order_file %t/ord-multiple-2
# RUN: llvm-objdump -d %t/test-2 | FileCheck %s --check-prefix=FOO-FIRST
# RUN: lld -flavor darwinnew -o %t/test-2 %t/foo.o %t/test.o -order_file %t/ord-multiple-2
# RUN: %lld -o %t/test-2 %t/foo.o %t/test.o -order_file %t/ord-multiple-2
# RUN: llvm-objdump -d %t/test-2 | FileCheck %s --check-prefix=FOO-FIRST

# RUN: echo "_foo" > %t/ord-multiple-3
# RUN: echo "_main" >> %t/ord-multiple-3
# RUN: echo "_foo" >> %t/ord-multiple-3
# RUN: lld -flavor darwinnew -o %t/test-3 %t/test.o %t/foo.o -order_file %t/ord-multiple-3
# RUN: %lld -o %t/test-3 %t/test.o %t/foo.o -order_file %t/ord-multiple-3
# RUN: llvm-objdump -d %t/test-3 | FileCheck %s --check-prefix=FOO-FIRST
# RUN: lld -flavor darwinnew -o %t/test-3 %t/foo.o %t/test.o -order_file %t/ord-multiple-3
# RUN: %lld -o %t/test-3 %t/foo.o %t/test.o -order_file %t/ord-multiple-3
# RUN: llvm-objdump -d %t/test-3 | FileCheck %s --check-prefix=FOO-FIRST

# RUN: echo "foo.o:_foo" > %t/ord-multiple-4
# RUN: echo "_main" >> %t/ord-multiple-4
# RUN: echo "foo.o:_foo" >> %t/ord-multiple-4
# RUN: lld -flavor darwinnew -o %t/test-4 %t/test.o %t/foo.o -order_file %t/ord-multiple-4
# RUN: %lld -o %t/test-4 %t/test.o %t/foo.o -order_file %t/ord-multiple-4
# RUN: llvm-objdump -d %t/test-4 | FileCheck %s --check-prefix=FOO-FIRST
# RUN: lld -flavor darwinnew -o %t/test-4 %t/foo.o %t/test.o -order_file %t/ord-multiple-4
# RUN: %lld -o %t/test-4 %t/foo.o %t/test.o -order_file %t/ord-multiple-4
# RUN: llvm-objdump -d %t/test-4 | FileCheck %s --check-prefix=FOO-FIRST

## _foo and _bar both point to the same location. When both symbols appear in
Expand All @@ -118,9 +118,9 @@
# RUN: echo "_bar" > %t/ord-alias
# RUN: echo "_main" >> %t/ord-alias
# RUN: echo "_foo" >> %t/ord-alias
# RUN: lld -flavor darwinnew -o %t/test-alias %t/test.o %t/foo.o -order_file %t/ord-alias
# RUN: %lld -o %t/test-alias %t/test.o %t/foo.o -order_file %t/ord-alias
# RUN: llvm-objdump -d %t/test-alias | FileCheck %s --check-prefix=FOO-FIRST
# RUN: lld -flavor darwinnew -o %t/test-alias %t/foo.o %t/test.o -order_file %t/ord-alias
# RUN: %lld -o %t/test-alias %t/foo.o %t/test.o -order_file %t/ord-alias
# RUN: llvm-objdump -d %t/test-alias | FileCheck %s --check-prefix=FOO-FIRST

.text
Expand Down
34 changes: 17 additions & 17 deletions lld/test/MachO/platform-version.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,56 +5,56 @@
### with bad version strings, so we use *-NOT patterns to ensure that
### no "malformed platform" diagnostic appears in those cases.

# RUN: not lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: not %lld -o %t %t.o 2>&1 \
# RUN: -platform_version \
# RUN: | FileCheck --check-prefix=FAIL-MISSING %s
# RUN: not lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: not %lld -o %t %t.o 2>&1 \
# RUN: -platform_version wtf \
# RUN: | FileCheck --check-prefix=FAIL-MISSING %s
# RUN: not lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: not %lld -o %t %t.o 2>&1 \
# RUN: -platform_version lolz 1.2.3.4.5 \
# RUN: | FileCheck --check-prefix=FAIL-MISSING %s
# FAIL-MISSING: -platform_version: missing argument
# FAIL-MISSING-NOT: malformed platform: {{.*}}
# FAIL-MISSING-NOT: malformed {{minimum|sdk}} version: {{.*}}

# RUN: not lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: not %lld -o %t %t.o 2>&1 \
# RUN: -platform_version macOS -lfoo 2 \
# RUN: | FileCheck --check-prefix=FAIL-MALFORM %s
# RUN: not lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: not %lld -o %t %t.o 2>&1 \
# RUN: -platform_version iOS 1 2.a \
# RUN: | FileCheck --check-prefix=FAIL-MALFORM %s
# RUN: not lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: not %lld -o %t %t.o 2>&1 \
# RUN: -platform_version tvOS 1.2.3.4.5 10 \
# RUN: | FileCheck --check-prefix=FAIL-MALFORM %s
# RUN: not lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: not %lld -o %t %t.o 2>&1 \
# RUN: -platform_version watchOS 10 1.2.3.4.5 \
# RUN: | FileCheck --check-prefix=FAIL-MALFORM %s
# FAIL-MALFORM-NOT: malformed platform: {{.*}}
# FAIL-MALFORM: malformed {{minimum|sdk}} version: {{.*}}

# RUN: lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: %lld -o %t %t.o 2>&1 \
# RUN: -platform_version bridgeOS 1 5
# RUN: lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: %lld -o %t %t.o 2>&1 \
# RUN: -platform_version "Mac Catalyst" 1.2 5.6
# RUN: lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: %lld -o %t %t.o 2>&1 \
# RUN: -platform_version "iOS Simulator" 1.2.3 5.6.7
# RUN: lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: %lld -o %t %t.o 2>&1 \
# RUN: -platform_version tvOS-Simulator 1.2.3.4 5.6.7.8
# RUN: lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: %lld -o %t %t.o 2>&1 \
# RUN: -platform_version watchOS-Simulator 1 5
# RUN: lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: %lld -o %t %t.o 2>&1 \
# RUN: -platform_version 1 1 5
# RUN: lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: %lld -o %t %t.o 2>&1 \
# RUN: -platform_version 9 1 5

# RUN: not lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: not %lld -o %t %t.o 2>&1 \
# RUN: -platform_version wtf 1 5 \
# RUN: | FileCheck --check-prefix=FAIL-PLATFORM %s
# RUN: not lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: not %lld -o %t %t.o 2>&1 \
# RUN: -platform_version 0 1 5 \
# RUN: | FileCheck --check-prefix=FAIL-PLATFORM %s
# RUN: not lld -flavor darwinnew -Z -o %t %t.o 2>&1 \
# RUN: not %lld -o %t %t.o 2>&1 \
# RUN: -platform_version 10 1 5 \
# RUN: | FileCheck --check-prefix=FAIL-PLATFORM %s
# FAIL-PLATFORM: malformed platform: {{.*}}
Expand Down
4 changes: 2 additions & 2 deletions lld/test/MachO/reexport-stub.s
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
## This test verifies that a non-TBD dylib can re-export a TBD library.

# RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/reexporter.o
# RUN: lld -flavor darwinnew -dylib -syslibroot %S/Inputs/MacOSX.sdk -lc++ -sub_library libc++ \
# RUN: %lld -dylib -lc++ -sub_library libc++ \
# RUN: %t/reexporter.o -o %t/libreexporter.dylib
# RUN: llvm-objdump --macho --all-headers %t/libreexporter.dylib | FileCheck %s --check-prefix=DYLIB-HEADERS
# DYLIB-HEADERS: cmd LC_REEXPORT_DYLIB
# DYLIB-HEADERS-NOT: Load command
# DYLIB-HEADERS: name /usr/lib/libc++.dylib

# RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %s -o %t/test.o
# RUN: lld -flavor darwinnew -o %t/test -syslibroot %S/Inputs/MacOSX.sdk -lSystem -L%t -lreexporter %t/test.o
# RUN: %lld -o %t/test -lSystem -L%t -lreexporter %t/test.o
# RUN: llvm-objdump --bind --no-show-raw-insn -d %t/test | FileCheck %s

# CHECK: Bind table:
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/relocations.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem -o %t %t.o
# RUN: %lld -lSystem -o %t %t.o
# RUN: llvm-objdump --section-headers --syms -d %t | FileCheck %s

# CHECK-LABEL: Sections:
Expand Down
10 changes: 5 additions & 5 deletions lld/test/MachO/resolution.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
# RUN: mkdir -p %t
# RUN: echo '.globl _foo, _bar, _baz; _foo: _bar: _baz:' | \
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/libresolution.o
# RUN: lld -flavor darwinnew -dylib -install_name \
# RUN: %lld -dylib -install_name \
# RUN: @executable_path/libresolution.dylib %t/libresolution.o -o %t/libresolution.dylib
# RUN: lld -flavor darwinnew -dylib -install_name \
# RUN: %lld -dylib -install_name \
# RUN: @executable_path/libresolution2.dylib %t/libresolution.o -o %t/libresolution2.dylib
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/resolution.o

## Check that we select the symbol defined in the first dylib passed on the
## command line.
# RUN: lld -flavor darwinnew -o %t/dylib-first -Z -L%t -lresolution -lresolution2 %t/resolution.o
# RUN: %lld -o %t/dylib-first -L%t -lresolution -lresolution2 %t/resolution.o
# RUN: llvm-objdump --macho --bind %t/dylib-first | FileCheck %s --check-prefix=DYLIB-FIRST
# DYLIB-FIRST: libresolution _foo

# RUN: lld -flavor darwinnew -o %t/dylib2-first -Z -L%t -lresolution2 -lresolution %t/resolution.o
# RUN: %lld -o %t/dylib2-first -L%t -lresolution2 -lresolution %t/resolution.o
# RUN: llvm-objdump --macho --bind %t/dylib2-first | FileCheck %s --check-prefix=DYLIB2-FIRST
# DYLIB2-FIRST: libresolution2 _foo

Expand All @@ -24,7 +24,7 @@

## Check that we pick the dylib symbol over the undefined symbol in the object
## file, even if the object file appears first on the command line.
# RUN: lld -flavor darwinnew -o %t/obj-first -Z -L%t %t/resolution.o -lresolution
# RUN: %lld -o %t/obj-first -L%t %t/resolution.o -lresolution
# RUN: llvm-objdump --macho --bind %t/obj-first | FileCheck %s --check-prefix=OBJ-FIRST
# OBJ-FIRST: libresolution _foo
## But defined symbols should still take precedence.
Expand Down
4 changes: 2 additions & 2 deletions lld/test/MachO/rpath.s
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -o %t %t.o
# RUN: %lld -o %t %t.o

## Check that -rpath generates LC_RPATH.
# RUN: lld -flavor darwinnew -o %t %t.o -rpath /some/rpath
# RUN: %lld -o %t %t.o -rpath /some/rpath
# RUN: llvm-objdump --macho --all-headers %t | FileCheck %s
# CHECK: LC_RPATH
# CHECK-NEXT: cmdsize 24
Expand Down
6 changes: 4 additions & 2 deletions lld/test/MachO/search-paths.test
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ UNSUPPORTED: darwin

RUN: mkdir -p %t1 %t2

RUN: lld -flavor darwinnew -Z -v -L%t1 -F%t2 2>&1 | FileCheck -DLDIR=%t1 -DFDIR=%t2 %s
RUN: %lld -v -L%t1 -F%t2 2>&1 | FileCheck -DLDIR=%t1 -DFDIR=%t2 %s
CHECK: Library search paths:
CHECK-NEXT: [[LDIR]]
CHECK-NEXT: /usr/lib
CHECK-NEXT: Framework search paths:
CHECK-NEXT: [[FDIR]]
CHECK-NEXT: /System/Library/Frameworks

RUN: lld -flavor darwinnew -Z -v -L%t1 -F%t2 -Z 2>&1 | FileCheck -DLDIR=%t1 -DFDIR=%t2 --check-prefix=CHECK_Z %s
RUN: %lld -v -L%t1 -F%t2 -Z 2>&1 | FileCheck -DLDIR=%t1 -DFDIR=%t2 --check-prefix=CHECK_Z %s
CHECK_Z: Library search paths:
CHECK_Z-NEXT: [[LDIR]]
CHECK_Z-NEXT: Framework search paths:
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/sectcreate.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# RUN: echo "-sectcreate 1.1" >%t1
# RUN: echo "-sectcreate 1.2" >%t2
# RUN: echo "-sectcreate 2" >%t3
# RUN: lld -flavor darwinnew -Z \
# RUN: %lld \
# RUN: -sectcreate SEG SEC1 %t1 \
# RUN: -sectcreate SEG SEC2 %t3 \
# RUN: -sectcreate SEG SEC1 %t2 \
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/section-headers.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -o %t %t.o
# RUN: %lld -o %t %t.o
# RUN: llvm-readobj --section-headers --macho-segment %t | FileCheck %s

# CHECK: Name: __text
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/section-merge.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# RUN: echo ".globl _baz; .data; .p2align 3; _baz: .byte 0xba" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/baz.o
# RUN: echo ".globl _qux; .data; .p2align 0; _qux: .quad 0xdeadbeef" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/qux.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/main.o
# RUN: lld -flavor darwinnew -o %t/output %t/foo.o %t/bar.o %t/baz.o %t/qux.o %t/main.o
# RUN: %lld -o %t/output %t/foo.o %t/bar.o %t/baz.o %t/qux.o %t/main.o

# RUN: llvm-objdump --syms --section=__data --full-contents %t/output | FileCheck %s
# CHECK: SYMBOL TABLE:
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/segments.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86, shell
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -o %t %t.o
# RUN: %lld -o %t %t.o
# RUN: (llvm-readobj --macho-segment %t; echo "Total file size"; wc -c %t) | FileCheck %s

## These two segments must always be present at the start of an executable.
Expand Down
9 changes: 6 additions & 3 deletions lld/test/MachO/silent-ignore.test
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
RUN: lld -flavor darwinnew -v \
RUN: %lld -v \
RUN: -demangle \
RUN: -dynamic \
RUN: -no_deduplicate \
RUN: -lto_library /lib/foo \
RUN: -macosx_version_min 0 \
RUN: -dependency_info /path/to/dependency_info.dat \
RUN: -mllvm -time-passes
RUN: not lld -flavor darwinnew -v --not-an-ignored-argument 2>&1 | FileCheck %s
RUN: -mllvm -time-passes \
RUN: -objc_abi_version 2 \
RUN: -ios_simulator_version_min 9.0.0 \
RUN: -sdk_version 13.2
RUN: not %lld -v --not-an-ignored-argument 2>&1 | FileCheck %s
CHECK: error: unknown argument: --not-an-ignored-argument
2 changes: 1 addition & 1 deletion lld/test/MachO/static-link.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# RUN: llvm-ar --format=darwin crs %t/libgoodbye.a %t/goodbye.o
#
# RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %s -o %t/test.o
# RUN: lld -flavor darwinnew -o %t/test -Z -L%t -lgoodbye %t/test.o
# RUN: %lld -o %t/test -L%t -lgoodbye %t/test.o
#
# RUN: llvm-objdump --syms -d -r %t/test | FileCheck %s

Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/stub-framework.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: mkdir -p %t
# RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %s -o %t/test.o
# RUN: lld -flavor darwinnew -o %t/test -Z -F%S/Inputs/MacOSX.sdk/System/Library/Frameworks -framework CoreFoundation %t/test.o
# RUN: %lld -o %t/test -framework CoreFoundation %t/test.o
#
# RUN: llvm-objdump --macho --dylibs-used %t/test | FileCheck %s
# CHECK: /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/stub-link.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# RUN: mkdir -p %t
#
# RUN: llvm-mc -filetype obj -triple x86_64-apple-darwin %s -o %t/test.o
# RUN: lld -flavor darwinnew -o %t/test -syslibroot %S/Inputs/MacOSX.sdk -lSystem -lc++ -framework CoreFoundation %t/test.o
# RUN: %lld -o %t/test -lSystem -lc++ -framework CoreFoundation %t/test.o
#
# RUN: llvm-objdump --bind --no-show-raw-insn -d -r %t/test | FileCheck %s

Expand Down
12 changes: 6 additions & 6 deletions lld/test/MachO/sub-library.s
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %p/Inputs/libgoodbye.s \
# RUN: -o %t/libgoodbye.o
# RUN: echo "" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/libsuper.o
# RUN: lld -flavor darwinnew -dylib %t/libhello.o -o %t/libhello.dylib
# RUN: lld -flavor darwinnew -dylib -L%t -sub_library libhello -lhello \
# RUN: %lld -dylib %t/libhello.o -o %t/libhello.dylib
# RUN: %lld -dylib -L%t -sub_library libhello -lhello \
# RUN: %t/libgoodbye.o -o %t/libgoodbye.dylib
# RUN: lld -flavor darwinnew -dylib -L%t -sub_library libgoodbye -lgoodbye -install_name \
# RUN: %lld -dylib -L%t -sub_library libgoodbye -lgoodbye -install_name \
# RUN: @executable_path/libsuper.dylib %t/libsuper.o -o %t/libsuper.dylib


Expand All @@ -37,7 +37,7 @@
# SUPER-HEADERS: name [[DIR]]/libgoodbye.dylib

# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/sub-library.o
# RUN: lld -flavor darwinnew -o %t/sub-library -L%t -lsuper %t/sub-library.o
# RUN: %lld -o %t/sub-library -L%t -lsuper %t/sub-library.o

# RUN: llvm-objdump --macho --bind %t/sub-library | FileCheck %s
# CHECK-LABEL: Bind table:
Expand All @@ -46,11 +46,11 @@


## Check that we fail gracefully if the sub-library is missing
# RUN: not lld -flavor darwinnew -dylib -Z -o %t/sub-library -sub_library libmissing %t/sub-library.o 2>&1 \
# RUN: not %lld -dylib -o %t/sub-library -sub_library libmissing %t/sub-library.o 2>&1 \
# RUN: | FileCheck %s --check-prefix=MISSING-SUB-LIBRARY
# MISSING-SUB-LIBRARY: error: -sub_library libmissing does not match a supplied dylib
# RUN: rm -f %t/libgoodbye.dylib
# RUN: not lld -flavor darwinnew -o %t/sub-library -Z -L%t -lsuper %t/sub-library.o 2>&1 \
# RUN: not %lld -o %t/sub-library -L%t -lsuper %t/sub-library.o 2>&1 \
# RUN: | FileCheck %s --check-prefix=MISSING-REEXPORT -DDIR=%t
# MISSING-REEXPORT: error: unable to locate re-export with install name [[DIR]]/libgoodbye.dylib

Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/subsections-section-relocs.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# RUN: echo "_bar_str" > %t/order-file
# RUN: echo "_foo_str" >> %t/order-file

# RUN: lld -flavor darwinnew -o %t/test %t/test.o -order_file %t/order-file
# RUN: %lld -o %t/test %t/test.o -order_file %t/order-file
# RUN: llvm-objdump --section-headers -d --no-show-raw-insn %t/test | FileCheck %s
# CHECK-LABEL: Sections:
# CHECK: __cstring {{[^ ]*}} {{0*}}[[#%x, CSTRING_ADDR:]]
Expand Down
4 changes: 2 additions & 2 deletions lld/test/MachO/subsections-symbol-relocs.s
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
# RUN: echo "_main" >> %t/order-file-2
# RUN: echo "_qux" >> %t/order-file-2

# RUN: lld -flavor darwinnew -o %t/test-1 %t/test.o -order_file %t/order-file-1
# RUN: %lld -o %t/test-1 %t/test.o -order_file %t/order-file-1
# RUN: llvm-objdump -d --no-show-raw-insn %t/test-1 | FileCheck %s
# RUN: lld -flavor darwinnew -o %t/test-2 %t/test.o -order_file %t/order-file-2
# RUN: %lld -o %t/test-2 %t/test.o -order_file %t/order-file-2
# RUN: llvm-objdump -d --no-show-raw-insn %t/test-2 | FileCheck %s
# CHECK-LABEL: Disassembly of section __TEXT,__text:
# CHECK: <_bar>:
Expand Down
8 changes: 4 additions & 4 deletions lld/test/MachO/symbol-order.s
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@
# RUN: echo ".global f; .section __TEXT,test_f2; f: ret" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/f2.o
# RUN: echo ".global f, g; .section __TEXT,test_fg; f: ret; g: callq f" | llvm-mc -filetype=obj -triple=x86_64-apple-darwin -o %t/fg.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -dylib -o %t/libf1.dylib %t/f1.o -lSystem
# RUN: %lld -dylib -o %t/libf1.dylib %t/f1.o -lSystem

# RUN: rm -f %t/libf2_g.a
# RUN: llvm-ar rcs %t/libf2_g.a %t/f2.o %t/g.o

# RUN: rm -f %t/libfg.a
# RUN: llvm-ar rcs %t/libfg.a %t/fg.o

# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib %t/libf1.dylib %t/libf2_g.a %t/test.o -o %t/test.out -lSystem
# RUN: %lld %t/libf1.dylib %t/libf2_g.a %t/test.o -o %t/test.out -lSystem
# RUN: llvm-objdump --syms --macho --lazy-bind %t/test.out | FileCheck %s --check-prefix DYLIB-FIRST
# DYLIB-FIRST: SYMBOL TABLE:
# DYLIB-FIRST-DAG: __TEXT,test_g g
# DYLIB-FIRST: Lazy bind table:
# DYLIB-FIRST-NEXT: segment section address dylib symbol
# DYLIB-FIRST-NEXT: __DATA __la_symbol_ptr {{[0-9a-z]+}} libf1 f

# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib %t/libf2_g.a %t/libf1.dylib %t/test.o -o %t/test.out -lSystem
# RUN: %lld %t/libf2_g.a %t/libf1.dylib %t/test.o -o %t/test.out -lSystem
# RUN: llvm-objdump --syms --macho --lazy-bind %t/test.out | FileCheck %s --check-prefix ARCHIVE-FIRST
# ARCHIVE-FIRST: SYMBOL TABLE:
# ARCHIVE-FIRST-DAG: __TEXT,test_f2 f
Expand All @@ -30,7 +30,7 @@
# ARCHIVE-FIRST-NEXT: segment section address dylib symbol
# ARCHIVE-FIRST-EMPTY:

# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib %t/libf1.dylib %t/libfg.a %t/test.o -o %t/test.out -lSystem
# RUN: %lld %t/libf1.dylib %t/libfg.a %t/test.o -o %t/test.out -lSystem
# RUN: llvm-objdump --syms --macho --lazy-bind %t/test.out | FileCheck %s --check-prefix ARCHIVE-PRIORITY
# ARCHIVE-PRIORITY: SYMBOL TABLE:
# ARCHIVE-PRIORITY-DAG: __TEXT,test_fg f
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/symtab.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t.o
# RUN: lld -flavor darwinnew -o %t %t.o
# RUN: %lld -o %t %t.o
# RUN: llvm-readobj -symbols %t | FileCheck %s

# CHECK: Symbols [
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/syslibroot.test
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ CHECK-ABSOLUTE-PATH-REROOTED: Library search paths:
CHECK-ABSOLUTE-PATH-REROOTED: [[ROOT]]/Library/libxml2-development
CHECK-ABSOLUTE-PATH-REROOTED: [[ROOT]]/usr/lib

RUN: lld -flavor darwinnew -v -Z -syslibroot %t -L %t/Library/libxml2-development | FileCheck %s -check-prefix CHECK-PATH-WITHOUT-REROOT -DPATH=%t/Library/libxml2-development
RUN: lld -flavor darwinnew -v -syslibroot %t -L %t/Library/libxml2-development | FileCheck %s -check-prefix CHECK-PATH-WITHOUT-REROOT -DPATH=%t/Library/libxml2-development
CHECK-PATH-WITHOUT-REROOT: Library search paths:
CHECK-PATH-WITHOUT-REROOT-NEXT: [[PATH]]

Expand Down
6 changes: 3 additions & 3 deletions lld/test/MachO/tlv-dylib.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# RUN: split-file %s %t

# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libtlv.s -o %t/libtlv.o
# RUN: lld -flavor darwinnew -dylib -install_name @executable_path/libtlv.dylib \
# RUN: -Z -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem -o %t/libtlv.dylib %t/libtlv.o
# RUN: %lld -dylib -install_name @executable_path/libtlv.dylib \
# RUN: -lSystem -o %t/libtlv.dylib %t/libtlv.o
# RUN: llvm-objdump --exports-trie -d --no-show-raw-insn %t/libtlv.dylib | FileCheck %s --check-prefix=DYLIB
# DYLIB-DAG: _foo [per-thread]
# DYLIB-DAG: _bar [per-thread]

# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
# RUN: lld -flavor darwinnew -Z -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem -L%t -ltlv %t/test.o -o %t/test
# RUN: %lld -lSystem -L%t -ltlv %t/test.o -o %t/test
# RUN: llvm-objdump --bind -d --no-show-raw-insn %t/test | FileCheck %s

# CHECK: movq [[#]](%rip), %rax # [[#%x, FOO:]]
Expand Down
2 changes: 1 addition & 1 deletion lld/test/MachO/tlv.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: mkdir -p %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %s -o %t/test.o
# RUN: lld -flavor darwinnew -L%S/Inputs/MacOSX.sdk/usr/lib -lSystem -o %t/test %t/test.o
# RUN: %lld -lSystem -o %t/test %t/test.o
# RUN: llvm-readobj --file-headers %t/test | FileCheck %s --check-prefix=HEADER
# RUN: llvm-objdump -D %t/test | FileCheck %s

Expand Down
4 changes: 2 additions & 2 deletions lld/test/MachO/weak-binding.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# RUN: split-file %s %t
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/test.s -o %t/test.o
# RUN: llvm-mc -filetype=obj -triple=x86_64-apple-darwin %t/libfoo.s -o %t/libfoo.o
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk -dylib %t/libfoo.o -o %t/libfoo.dylib
# RUN: lld -flavor darwinnew -syslibroot %S/Inputs/MacOSX.sdk %t/test.o -L%t -lfoo -o %t/test -lSystem
# RUN: %lld -dylib %t/libfoo.o -o %t/libfoo.dylib
# RUN: %lld %t/test.o -L%t -lfoo -o %t/test -lSystem
# RUN: llvm-objdump -d --no-show-raw-insn --bind --lazy-bind --weak-bind --full-contents %t/test | \
# RUN: FileCheck %s

Expand Down
Loading