From 233f5377999892630b8869a6010638b5d9b6ddc7 Mon Sep 17 00:00:00 2001 From: Nick Kledzik Date: Tue, 15 Jan 2013 00:17:57 +0000 Subject: Add new merge-by-content Merge attribute for use by anonymous constants and string literals which the linker should coalesce. llvm-svn: 172495 --- lld/lib/Core/SymbolTable.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'lld/lib/Core/SymbolTable.cpp') diff --git a/lld/lib/Core/SymbolTable.cpp b/lld/lib/Core/SymbolTable.cpp index b3fe8e8a50e..1c7ea99ff05 100644 --- a/lld/lib/Core/SymbolTable.cpp +++ b/lld/lib/Core/SymbolTable.cpp @@ -46,11 +46,16 @@ void SymbolTable::add(const AbsoluteAtom &atom) { } void SymbolTable::add(const DefinedAtom &atom) { - assert(atom.scope() != DefinedAtom::scopeTranslationUnit); - if ( !atom.name().empty() ) { + if (!atom.name().empty() && + (atom.scope() != DefinedAtom::scopeTranslationUnit)) { + // Named atoms cannot be merged by content. + assert(atom.merge() != DefinedAtom::mergeByContent); + // Track named atoms that are not scoped to file (static). this->addByName(atom); } - else { + else if ( atom.merge() == DefinedAtom::mergeByContent ) { + // Named atoms cannot be merged by content. + assert(atom.name().empty()); this->addByContent(atom); } } @@ -123,6 +128,7 @@ static MergeResolution mergeSelect(DefinedAtom::Merge first, void SymbolTable::addByName(const Atom & newAtom) { StringRef name = newAtom.name(); + assert(!name.empty()); const Atom *existing = this->findByName(name); if (existing == nullptr) { // Name is not in symbol table yet, add it associate with this atom. @@ -283,6 +289,8 @@ bool SymbolTable::AtomMappingInfo::isEqual(const DefinedAtom * const l, } void SymbolTable::addByContent(const DefinedAtom & newAtom) { + // Currently only read-only constants can be merged. + assert(newAtom.permissions() == DefinedAtom::permR__); AtomContentSet::iterator pos = _contentTable.find(&newAtom); if ( pos == _contentTable.end() ) { _contentTable.insert(&newAtom); -- cgit v1.2.3