[lld] r210624 - [mach-o] fix use of resolver functions to not cause duplicate sections.

Nick Kledzik kledzik at apple.com
Tue Jun 10 18:30:55 PDT 2014


Author: kledzik
Date: Tue Jun 10 20:30:55 2014
New Revision: 210624

URL: http://llvm.org/viewvc/llvm-project?rev=210624&view=rev
Log:
[mach-o] fix use of resolver functions to not cause duplicate sections.

The previous commit uncovered a bug in the mach-o writer whereby two __text
sections were created.  But the test case did not catch that.  So I updated
the test case to run the linker a second time, reading the output of the
first pass.  


Modified:
    lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
    lld/trunk/test/mach-o/parse-function.yaml

Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp?rev=210624&r1=210623&r2=210624&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp Tue Jun 10 20:30:55 2014
@@ -113,8 +113,8 @@ private:
   typedef llvm::StringMap<DylibInfo> DylibPathToInfo;
 
   SectionInfo *sectionForAtom(const DefinedAtom*);
-  SectionInfo *makeRelocatableSection(DefinedAtom::ContentType type);
-  SectionInfo *makeFinalSection(DefinedAtom::ContentType type);
+  SectionInfo *getRelocatableSection(DefinedAtom::ContentType type);
+  SectionInfo *getFinalSection(DefinedAtom::ContentType type);
   void         appendAtom(SectionInfo *sect, const DefinedAtom *atom);
   SegmentInfo *segmentForName(StringRef segName);
   void         layoutSectionsInSegment(SegmentInfo *seg, uint64_t &addr);
@@ -160,7 +160,7 @@ private:
 };
 
 
-SectionInfo *Util::makeRelocatableSection(DefinedAtom::ContentType type) {
+SectionInfo *Util::getRelocatableSection(DefinedAtom::ContentType type) {
   StringRef segmentName;
   StringRef sectionName;
   SectionType sectionType;
@@ -178,8 +178,11 @@ SectionInfo *Util::makeRelocatableSectio
     }
   }
   // Otherwise allocate new SectionInfo object.
-  return new (_allocator) SectionInfo(segmentName, sectionName, sectionType, 
-                                      sectionAttrs);
+  SectionInfo *sect = new (_allocator) SectionInfo(segmentName, sectionName, 
+                                                   sectionType, sectionAttrs);
+  _sectionInfos.push_back(sect);
+  _sectionMap[type] = sect;
+  return sect;
 }
 
 #define ENTRY(seg, sect, type, atomType) \
@@ -220,7 +223,7 @@ const MachOFinalSectionFromAtomType sect
 #undef ENTRY
 
 
-SectionInfo *Util::makeFinalSection(DefinedAtom::ContentType atomType) {
+SectionInfo *Util::getFinalSection(DefinedAtom::ContentType atomType) {
   for (const MachOFinalSectionFromAtomType *p = sectsToAtomType ;
                                  p->atomType != DefinedAtom::typeUnknown; ++p) {
     if (p->atomType != atomType)
@@ -243,8 +246,13 @@ SectionInfo *Util::makeFinalSection(Defi
       }
     }
     // Otherwise allocate new SectionInfo object.
-    return new (_allocator) SectionInfo(p->segmentName, p->sectionName, 
-                                        p->sectionType, sectionAttrs);
+    SectionInfo *sect = new (_allocator) SectionInfo(p->segmentName, 
+                                                     p->sectionName, 
+                                                     p->sectionType, 
+                                                     sectionAttrs);
+    _sectionInfos.push_back(sect);
+    _sectionMap[atomType] = sect;
+    return sect;
   }
   llvm_unreachable("content type not yet supported");
 }
@@ -259,11 +267,7 @@ SectionInfo *Util::sectionForAtom(const
     if ( pos != _sectionMap.end() )
       return pos->second;
     bool rMode = (_context.outputFileType() == llvm::MachO::MH_OBJECT);
-    SectionInfo *si = rMode ? makeRelocatableSection(type) 
-                            : makeFinalSection(type);
-    _sectionInfos.push_back(si);
-    _sectionMap[type] = si;
-    return si;
+    return rMode ? getRelocatableSection(type) : getFinalSection(type);
   } else {
     // This atom needs to be in a custom section.
     StringRef customName = atom->customSectionName();
@@ -619,7 +623,12 @@ bool Util::AtomSorter::operator()(const
 
 
 bool Util::belongsInGlobalSymbolsSection(const DefinedAtom* atom) {
-  return (atom->scope() == Atom::scopeGlobal);
+  // ScopeLinkageUnit symbols are in globals area of symbol table
+  // in object files, but in locals area for final linked images. 
+  if (_context.outputFileType() == llvm::MachO::MH_OBJECT)
+    return (atom->scope() != Atom::scopeTranslationUnit);
+  else
+    return (atom->scope() == Atom::scopeGlobal);
 }
 
 void Util::addSymbols(const lld::File &atomFile, NormalizedFile &file) {

Modified: lld/trunk/test/mach-o/parse-function.yaml
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/mach-o/parse-function.yaml?rev=210624&r1=210623&r2=210624&view=diff
==============================================================================
--- lld/trunk/test/mach-o/parse-function.yaml (original)
+++ lld/trunk/test/mach-o/parse-function.yaml Tue Jun 10 20:30:55 2014
@@ -1,4 +1,5 @@
-# RUN: lld -flavor darwin -arch x86_64 -r -print_atoms %s -o %t  | FileCheck %s
+# RUN: lld -flavor darwin -arch x86_64 -r %s -o %t  
+# RUN: lld -flavor darwin -arch x86_64 -r %t -print_atoms -o %t2 | FileCheck %s
 #
 # Test parsing of mach-o functions.
 #





More information about the llvm-commits mailing list