#include <vector>
#include <list>
#include <algorithm>
-#include <ext/hash_map>
-#include <ext/hash_set>
#include <dlfcn.h>
#include <AvailabilityMacros.h>
class DSOHandleAtom : public ld::Atom {
public:
DSOHandleAtom(const char* nm, ld::Atom::Scope sc,
- ld::Atom::SymbolTableInclusion inc, bool preload=false)
- : ld::Atom(preload ? _s_section_preload : _s_section,
- ld::Atom::definitionRegular, ld::Atom::combineNever,
+ ld::Atom::SymbolTableInclusion inc, ld::Section& sect=_s_section)
+ : ld::Atom(sect, ld::Atom::definitionRegular,
+ (sect == _s_section_text) ? ld::Atom::combineByName : ld::Atom::combineNever,
+ // make "weak def" so that link succeeds even if app defines __dso_handle
sc, ld::Atom::typeUnclassified, inc, true, false, false,
ld::Atom::Alignment(1)), _name(nm) {}
virtual ld::File* file() const { return NULL; }
- virtual bool translationUnitSource(const char** dir, const char** ) const
- { return false; }
- virtual const char* name() const { return _name; }
+ virtual const char* name() const { return _name; }
virtual uint64_t size() const { return 0; }
virtual uint64_t objectAddress() const { return 0; }
virtual void copyRawContent(uint8_t buffer[]) const
static ld::Section _s_section;
static ld::Section _s_section_preload;
+ static ld::Section _s_section_text;
static DSOHandleAtom _s_atomAll;
static DSOHandleAtom _s_atomExecutable;
static DSOHandleAtom _s_atomDylib;
static DSOHandleAtom _s_atomDyld;
static DSOHandleAtom _s_atomObjectFile;
static DSOHandleAtom _s_atomPreload;
+ static DSOHandleAtom _s_atomPreloadDSO;
private:
const char* _name;
};
ld::Section DSOHandleAtom::_s_section("__TEXT", "__mach_header", ld::Section::typeMachHeader, true);
ld::Section DSOHandleAtom::_s_section_preload("__HEADER", "__mach_header", ld::Section::typeMachHeader, true);
+ld::Section DSOHandleAtom::_s_section_text("__TEXT", "__text", ld::Section::typeCode, false);
DSOHandleAtom DSOHandleAtom::_s_atomAll("___dso_handle", ld::Atom::scopeLinkageUnit, ld::Atom::symbolTableNotIn);
DSOHandleAtom DSOHandleAtom::_s_atomExecutable("__mh_execute_header", ld::Atom::scopeGlobal, ld::Atom::symbolTableInAndNeverStrip);
DSOHandleAtom DSOHandleAtom::_s_atomDylib("__mh_dylib_header", ld::Atom::scopeLinkageUnit, ld::Atom::symbolTableNotIn);
DSOHandleAtom DSOHandleAtom::_s_atomBundle("__mh_bundle_header", ld::Atom::scopeLinkageUnit, ld::Atom::symbolTableNotIn);
DSOHandleAtom DSOHandleAtom::_s_atomDyld("__mh_dylinker_header", ld::Atom::scopeLinkageUnit, ld::Atom::symbolTableNotIn);
DSOHandleAtom DSOHandleAtom::_s_atomObjectFile("__mh_object_header", ld::Atom::scopeLinkageUnit, ld::Atom::symbolTableNotIn);
-DSOHandleAtom DSOHandleAtom::_s_atomPreload("__mh_preload_header", ld::Atom::scopeLinkageUnit, ld::Atom::symbolTableNotIn, true);
+DSOHandleAtom DSOHandleAtom::_s_atomPreload("__mh_preload_header", ld::Atom::scopeLinkageUnit, ld::Atom::symbolTableNotIn, _s_section_preload);
+DSOHandleAtom DSOHandleAtom::_s_atomPreloadDSO("___dso_handle", ld::Atom::scopeLinkageUnit, ld::Atom::symbolTableNotIn, _s_section_text);
_size(sz) {}
virtual ld::File* file() const { return NULL; }
- virtual bool translationUnitSource(const char** dir, const char** ) const
- { return false; }
virtual const char* name() const { return "page zero"; }
virtual uint64_t size() const { return _size; }
virtual uint64_t objectAddress() const { return 0; }
_size(sz) {}
virtual ld::File* file() const { return NULL; }
- virtual bool translationUnitSource(const char** dir, const char** ) const
- { return false; }
virtual const char* name() const { return "custom stack"; }
virtual uint64_t size() const { return _size; }
virtual uint64_t objectAddress() const { return 0; }
}
// see if it is an llvm object file
- objResult = lto::parse(p, len, info.path, info.modTime, _options.architecture(), _options.subArchitecture(), _options.logAllFiles());
+ objResult = lto::parse(p, len, info.path, info.modTime, info.ordinal, _options.architecture(), _options.subArchitecture(), _options.logAllFiles());
if ( objResult != NULL ) {
OSAtomicAdd64(len, &_totalObjectSize);
OSAtomicIncrement32(&_totalObjectLoaded);
throwf("indirect dylib at %s is not a dylib", info.path);
}
catch (const char* msg) {
- throwf("in %s, %s", info.path, msg);
+ throwf("in '%s', %s", info.path, msg);
}
}
}
: _totalObjectSize(0), _totalArchiveSize(0),
_totalObjectLoaded(0), _totalArchivesLoaded(0), _totalDylibsLoaded(0),
_options(opts), _bundleLoader(NULL),
- _allDirectDylibsLoaded(false), _inferredArch(false), _fileMonitor(-1),
+ _allDirectDylibsLoaded(false), _inferredArch(false),
_exception(NULL)
{
// fStartCreateReadersTime = mach_absolute_time();
// update stats
_totalDylibsLoaded++;
- _searchLibraries.push_back(LibraryInfo(reader));
+ // just add direct libraries to search-first list
+ if ( !_allDirectDylibsLoaded )
+ _searchLibraries.push_back(LibraryInfo(reader));
return reader;
}
case Options::kPreload:
// add implicit __mh_preload_header label
handler.doAtom(DSOHandleAtom::_s_atomPreload);
- handler.doAtom(DSOHandleAtom::_s_atomAll);
+ // add implicit __dso_handle label, but put it in __text section because
+ // with -preload the mach_header is no in the address space.
+ handler.doAtom(DSOHandleAtom::_s_atomPreloadDSO);
break;
case Options::kObjectFile:
handler.doAtom(DSOHandleAtom::_s_atomObjectFile);
bool InputFiles::searchLibraries(const char* name, bool searchDylibs, bool searchArchives, bool dataSymbolOnly, ld::File::AtomHandler& handler) const
{
// Check each input library.
- std::vector<LibraryInfo>::const_iterator libIterator = _searchLibraries.begin();
-
-
- while (libIterator != _searchLibraries.end()) {
- LibraryInfo lib = *libIterator;
+ for (std::vector<LibraryInfo>::const_iterator it=_searchLibraries.begin(); it != _searchLibraries.end(); ++it) {
+ LibraryInfo lib = *it;
if (lib.isDylib()) {
if (searchDylibs) {
ld::dylib::File *dylibFile = lib.dylib();
}
}
}
- libIterator++;
}
// search indirect dylibs