[lld] r200649 - [MachO] Add undefined atoms.
Joey Gouly
joey.gouly at gmail.com
Sun Feb 2 11:34:55 PST 2014
Author: joey
Date: Sun Feb 2 13:34:55 2014
New Revision: 200649
URL: http://llvm.org/viewvc/llvm-project?rev=200649&view=rev
Log:
[MachO] Add undefined atoms.
Modified:
lld/trunk/lib/ReaderWriter/MachO/File.h
lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
lld/trunk/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
Modified: lld/trunk/lib/ReaderWriter/MachO/File.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/File.h?rev=200649&r1=200648&r2=200649&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/File.h (original)
+++ lld/trunk/lib/ReaderWriter/MachO/File.h Sun Feb 2 13:34:55 2014
@@ -37,6 +37,18 @@ public:
addAtom(*atom);
}
+ void addUndefinedAtom(StringRef name, bool copyRefs) {
+ if (copyRefs) {
+ // Make a copy of the atom's name and content that is owned by this file.
+ char *s = _allocator.Allocate<char>(name.size());
+ memcpy(s, name.data(), name.size());
+ name = StringRef(s, name.size());
+ }
+ SimpleUndefinedAtom *atom =
+ new (_allocator) SimpleUndefinedAtom(*this, name);
+ addAtom(*atom);
+ }
+
private:
llvm::BumpPtrAllocator _allocator;
};
Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp?rev=200649&r1=200648&r2=200649&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileToAtoms.cpp Sun Feb 2 13:34:55 2014
@@ -98,8 +98,9 @@ normalizedObjectToAtoms(const Normalized
processSymbol(normalizedFile, *file, sym, copyRefs);
}
- assert(normalizedFile.undefinedSymbols.empty() &&
- "undefined symbols not supported yet!");
+ for (auto &sym : normalizedFile.undefinedSymbols) {
+ file->addUndefinedAtom(sym.name, copyRefs);
+ }
return std::unique_ptr<File>(std::move(file));
}
Modified: lld/trunk/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp?rev=200649&r1=200648&r2=200649&view=diff
==============================================================================
--- lld/trunk/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp (original)
+++ lld/trunk/unittests/MachOTests/MachONormalizedFileToAtomsTests.cpp Sun Feb 2 13:34:55 2014
@@ -23,8 +23,8 @@ using namespace llvm::MachO;
TEST(ToAtomsTest, empty_obj_x86_64) {
NormalizedFile f;
f.arch = lld::MachOLinkingContext::arch_x86_64;
- ErrorOr<std::unique_ptr<const lld::File>> atom_f = normalizedToAtoms(f, "",
- false);
+ ErrorOr<std::unique_ptr<const lld::File>> atom_f =
+ normalizedToAtoms(f, "", false);
EXPECT_FALSE(!atom_f);
EXPECT_EQ(0U, (*atom_f)->defined().size());
}
@@ -51,6 +51,10 @@ TEST(ToAtomsTest, basic_obj_x86_64) {
barSymbol.sect = 1;
barSymbol.value = 2;
f.globalSymbols.push_back(barSymbol);
+ Symbol undefSym;
+ undefSym.name = "_undef";
+ undefSym.type = N_UNDF;
+ f.undefinedSymbols.push_back(undefSym);
Symbol bazSymbol;
bazSymbol.name = "_baz";
bazSymbol.type = N_SECT;
@@ -59,8 +63,8 @@ TEST(ToAtomsTest, basic_obj_x86_64) {
bazSymbol.value = 3;
f.localSymbols.push_back(bazSymbol);
- ErrorOr<std::unique_ptr<const lld::File>> atom_f = normalizedToAtoms(f, "",
- false);
+ ErrorOr<std::unique_ptr<const lld::File>> atom_f =
+ normalizedToAtoms(f, "", false);
EXPECT_FALSE(!atom_f);
const lld::File &file = **atom_f;
EXPECT_EQ(3U, file.defined().size());
@@ -70,6 +74,7 @@ TEST(ToAtomsTest, basic_obj_x86_64) {
const lld::DefinedAtom *atom2 = *it;
++it;
const lld::DefinedAtom *atom3 = *it;
+ const lld::UndefinedAtom *atom4 = *file.undefined().begin();
EXPECT_TRUE(atom1->name().equals("_foo"));
EXPECT_EQ(2U, atom1->rawContent().size());
EXPECT_EQ(0x90, atom1->rawContent()[0]);
@@ -85,4 +90,7 @@ TEST(ToAtomsTest, basic_obj_x86_64) {
EXPECT_EQ(1U, atom3->rawContent().size());
EXPECT_EQ(0xC4, atom3->rawContent()[0]);
EXPECT_EQ(lld::Atom::scopeLinkageUnit, atom3->scope());
+
+ EXPECT_TRUE(atom4->name().equals("_undef"));
+ EXPECT_EQ(lld::Atom::definitionUndefined, atom4->definition());
}
More information about the llvm-commits
mailing list