add ld64-port comments to changed code + some cleanup

This commit is contained in:
Thomas Pöchtrager 2015-07-11 08:44:07 +02:00
parent 74daaf79d3
commit ddd711afa0
19 changed files with 53 additions and 50 deletions

View File

@ -1,7 +1,7 @@
SUBDIRS = BlocksRuntime
noinst_LTLIBRARIES = libhelper.la
noinst_HEADERS = helper.h strlcat.h strlcpy.h qsort_r.h
libhelper_la_CFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/include/foreign $(ENDIAN_FLAG)
libhelper_la_CFLAGS=-I$(top_srcdir)/include -I$(top_srcdir)/include/foreign $(ENDIAN_FLAG) $(WARNINGS)
libhelper_la_SOURCES = \
helper.c \

View File

@ -6,6 +6,8 @@
extern "C" {
#endif
void qsort_r_local(void *base, size_t nmemb, size_t size, void *thunk, int (*compar)(void *, const void *, const void *));
#undef qsort_r
#define qsort_r qsort_r_local
#if defined(__cplusplus)
};
#endif

View File

@ -32,6 +32,7 @@
#include <vector>
// ld64-port start
#if defined(__arm__) || defined(__arm64__)
#undef THREAD_STATE_NONE
#undef VALID_THREAD_STATE_FLAVOR
@ -40,6 +41,7 @@
#endif
#include <mach/i386/thread_status.h>
// ld64-port end
#include "MachOFileAbstraction.hpp"
#include "Options.h"

View File

@ -365,7 +365,12 @@ ld::File* InputFiles::makeFile(const Options::FileInfo& info, bool indirectDylib
throwf("lto file was built for %s which is not the architecture being linked (%s): %s", fileArch(p, len), _options.architectureName(), info.path);
}
else {
const char* libLTO = "libLTO.so";
#ifdef __APPLE__ // ld64-port
const char* libLTO = "libLTO.dylib";
#else
const char* libLTO = "libLTO.so";
#endif /* __APPLE__ */
char ldPath[PATH_MAX];
char tmpPath[PATH_MAX];
char libLTOPath[PATH_MAX];

View File

@ -42,7 +42,7 @@
#include "MachOFileAbstraction.hpp"
#include "Snapshot.h"
#include <ctype.h>
#include <ctype.h> // ld64-port
// upward dependency on lto::version()
namespace lto {
@ -52,7 +52,7 @@ namespace lto {
// magic to place command line in crash reports
const int crashreporterBufferSize = 2000;
static char crashreporterBuffer[crashreporterBufferSize];
#if defined(__has_include) && __has_include(<CrashReporterClient.h>)
#if defined(__has_include) && __has_include(<CrashReporterClient.h>) // ld64-port
#define HAVE_CRASHREPORTER_HEADER 1
#else
#define HAVE_CRASHREPORTER_HEADER 0
@ -1773,7 +1773,7 @@ void Options::addSection(const char* segment, const char* section, const char* p
::close(fd);
// record section to create
ExtraSection info = { segment, section, path, (uint8_t*)p, static_cast<uint64_t>(stat_buf.st_size) };
ExtraSection info = { segment, section, path, (uint8_t*)p, static_cast<uint64_t>(stat_buf.st_size) }; // ld64-port: stat_buf.st_size -> static_cast<uint64_t>(stat_buf.st_size)
fExtraSections.push_back(info);
}
@ -2478,9 +2478,9 @@ void Options::parse(int argc, const char* argv[])
else if ( (strcmp(arg, "-ios_version_min") == 0) || (strcmp(arg, "-iphoneos_version_min") == 0) ) {
setIOSVersionMin(argv[++i]);
}
else if ( (strcmp(arg, "-aspen_version_min") == 0) ) {
//for backward compitable with llvm-gcc.
++i;
else if ( (strcmp(arg, "-aspen_version_min") == 0) ) { // ld64-port
// for backward compatibility with llvm-gcc.
++i;
}
else if ( strcmp(arg, "-ios_simulator_version_min") == 0 ) {
setIOSVersionMin(argv[++i]);
@ -4274,7 +4274,7 @@ void Options::reconfigureDefaults()
fSDKVersion = fMacVersionMin;
}
else {
#ifdef __APPLE__
#ifdef __APPLE__ // ld64-port
int mib[2] = { CTL_KERN, KERN_OSRELEASE };
char kernVersStr[100];
size_t strlen = sizeof(kernVersStr);
@ -4285,7 +4285,7 @@ void Options::reconfigureDefaults()
uint32_t kernVers = parseVersionNumber32(kernVersStr);
int minor = (kernVers >> 16) - 4; // kernel major version is 4 ahead of x in 10.x
fSDKVersion = 0x000A0000 + (minor << 8);
#ifdef __APPLE__
#ifdef __APPLE__ // ld64-port
}
#endif
}
@ -4604,7 +4604,7 @@ void Options::checkIllegalOptionCombinations()
// make sure all required exported symbols exist
std::vector<const char*> impliedExports;
for (NameSet::const_iterator it=fExportSymbols.regularBegin(); it != fExportSymbols.regularEnd(); ++it) {
for (NameSet::const_iterator it=fExportSymbols.regularBegin(); it != fExportSymbols.regularEnd(); ++it) { // ld64-port: NameSet::iterator it -> NameSet::const_iterator it
const char* name = *it;
const int len = strlen(name);
if ( (strcmp(&name[len-3], ".eh") == 0) || (strncmp(name, ".objc_category_name_", 20) == 0) ) {
@ -4636,7 +4636,7 @@ void Options::checkIllegalOptionCombinations()
}
// make sure all required re-exported symbols exist
for (NameSet::const_iterator it=fReExportSymbols.regularBegin(); it != fReExportSymbols.regularEnd(); ++it) {
for (NameSet::const_iterator it=fReExportSymbols.regularBegin(); it != fReExportSymbols.regularEnd(); ++it) { // ld64-port: NameSet::iterator it -> NameSet::const_iterator it
fInitialUndefines.push_back(*it);
}
@ -4836,7 +4836,7 @@ void Options::checkForClassic(int argc, const char* argv[])
bool newLinker = false;
// build command line buffer in case ld crashes
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 && HAVE_CRASHREPORTER_HEADER
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1070 && HAVE_CRASHREPORTER_HEADER // ld64-port: added && HAVE_CRASHREPORTER_HEADER
CRSetCrashLogMessage(crashreporterBuffer);
#endif
const char* srcRoot = getenv("SRCROOT");
@ -4895,7 +4895,7 @@ void Options::checkForClassic(int argc, const char* argv[])
void Options::gotoClassicLinker(int argc, const char* argv[])
{
argv[0] = PROGRAM_PREFIX "ld_classic";
argv[0] = PROGRAM_PREFIX "ld_classic"; // ld64-port: added PROGRAM_PREFIX
// ld_classic does not support -iphoneos_version_min, so change
for(int j=0; j < argc; ++j) {
if ( (strcmp(argv[j], "-iphoneos_version_min") == 0) || (strcmp(argv[j], "-ios_version_min") == 0) ) {

View File

@ -411,8 +411,8 @@ private:
bool containsNonWildcard(const char*) const;
bool empty() const { return fRegular.empty() && fWildCard.empty(); }
bool hasWildCards() const { return !fWildCard.empty(); }
NameSet::const_iterator regularBegin() const { return fRegular.begin(); }
NameSet::const_iterator regularEnd() const { return fRegular.end(); }
NameSet::const_iterator regularBegin() const { return fRegular.begin(); } // ld64-port: NameSet::iterator -> NameSet::const_iterator
NameSet::const_iterator regularEnd() const { return fRegular.end(); } // ld64-port: NameSet::iterator -> NameSet::const_iterator
void remove(const NameSet&);
private:
static bool hasWildCards(const char*);

View File

@ -2683,7 +2683,7 @@ void OutputFile::writeOutputFile(ld::Internal& state)
if (stat_buf.st_mode & S_IFREG) {
outputIsRegularFile = true;
// <rdar://problem/12264302> Don't use mmap on non-hfs volumes
#if 0
#ifdef __APPLE__ // ld64-port
struct statfs fsInfo;
if ( statfs(_options.outputFilePath(), &fsInfo) != -1 ) {
if ( strcmp(fsInfo.f_fstypename, "hfs") == 0) {
@ -2692,11 +2692,11 @@ void OutputFile::writeOutputFile(ld::Internal& state)
}
}
else {
#endif
#endif /* __APPLE__ */
outputIsMappableFile = false;
#if 0
#ifdef __APPLE__ // ld64-port
}
#endif
#endif /* __APPLE__ */
}
else {
outputIsRegularFile = false;

View File

@ -1626,7 +1626,7 @@ void Resolver::linkTimeOptimize()
this->checkDylibSymbolCollisions();
}
#else
throw "";
throwf("no builtin LTO support"); // ld64-port
#endif /* LTO_SUPPORT */
}

View File

@ -417,7 +417,6 @@ bool SymbolTable::addByName(const ld::Atom& newAtom, bool ignoreDuplicates)
const ld::Atom* existingAtom = _indirectBindingTable[slot];
//fprintf(stderr, "addByName(%p) name=%s, slot=%u, existing=%p\n", &newAtom, newAtom.name(), slot, existingAtom);
if ( existingAtom != NULL ) {
assert(&newAtom != existingAtom);
NameCollisionResolution picker(newAtom, *existingAtom, ignoreDuplicates, _options);
if (picker.reportDuplicate()) {

View File

@ -45,13 +45,8 @@
#include "endian.h"
#include "memutils.h"
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
namespace std {
typedef ::FILE FILE;
}
#include <cstdio>
#include <cstring> // ld64-port
namespace Security {

View File

@ -32,7 +32,7 @@
#include <libkern/OSByteOrder.h>
//#include <security_utilities/utilities.h>
#include "memutils.h"
#include <arpa/inet.h>
#include <arpa/inet.h> // ld64-port
namespace Security {

View File

@ -33,7 +33,7 @@
#include <stdlib.h>
#include <algorithm>
#ifdef __GLIBCXX__
#ifdef __GLIBCXX__ // ld64-port
using namespace __gnu_cxx;
#endif
@ -49,7 +49,7 @@ namespace LowLevelMemoryUtilities {
//
static const size_t systemAlignment = 4;
#ifndef __GXX_EXPERIMENTAL_CXX0X__
#ifndef __GXX_EXPERIMENTAL_CXX0X__ // ld64-port
//
// Get the local alignment for a type, as used by the acting compiler.
//

View File

@ -23,7 +23,7 @@
*/
// start temp HACK for cross builds
//extern "C" double log2 ( double );
//extern "C" double log2 ( double ); // ld64-port: commented
//#define __MATH__
// end temp HACK for cross builds
@ -1151,7 +1151,7 @@ int main(int argc, const char* argv[])
fprintf(stderr, "processed %3u dylib files\n", inputFiles._totalDylibsLoaded);
fprintf(stderr, "wrote output file totaling %15s bytes\n", commatize(out.fileSize(), temp));
}
if ( getenv("IOS_SIGN_CODE_WHEN_BUILD") || getenv("IOS_FAKE_CODE_SIGN") ) {
if ( getenv("IOS_SIGN_CODE_WHEN_BUILD") || getenv("IOS_FAKE_CODE_SIGN") ) { // ld64-port (keep IOS_SIGN_CODE_WHEN_BUILD for compatibility with the 'iOS toolchain based on clang for linux' project)
std::string ldid = std::string("ldid -S ") + std::string(options.outputFilePath());
system(ldid.c_str());
}
@ -1179,7 +1179,7 @@ int main(int argc, const char* argv[])
// implement assert() function to print out a backtrace before aborting
void __assert_rtn(const char* func, const char* file, int line, const char* failedexpr)
{
#if __has_include(<execinfo.h>)
#if __has_include(<execinfo.h>) // ld64-port
Snapshot *snapshot = Snapshot::globalSnapshot;
snapshot->setSnapshotMode(Snapshot::SNAPSHOT_DEBUG);

View File

@ -35,7 +35,7 @@
#include <vector>
#include <unordered_set>
#include "configure.h"
#include "configure.h" // ld64-port
namespace ld {

View File

@ -37,7 +37,7 @@
#include <mach-o/getsect.h>
#include <mach-o/dyld_priv.h>
#if defined(__arm__) || defined(__arm64__)
#if defined(__arm__) || defined(__arm64__) // ld64-port
#undef THREAD_STATE_NONE
#undef VALID_THREAD_STATE_FLAVOR
#undef MACHINE_THREAD_STATE

View File

@ -36,7 +36,7 @@
#include <mach-o/loader.h>
#include <mach-o/getsect.h>
#if defined(__arm__) || defined(__arm64__)
#if defined(__arm__) || defined(__arm64__) // ld64-port
#undef THREAD_STATE_NONE
#undef VALID_THREAD_STATE_FLAVOR
#undef MACHINE_THREAD_STATE

View File

@ -33,7 +33,7 @@
#include <sys/fcntl.h>
#include <sys/stat.h>
#include <errno.h>
#include <pthread.h>
#include <pthread.h> // ld64-port
#include <mach-o/dyld.h>
#include <vector>
#include <unordered_set>
@ -46,8 +46,8 @@
#include "lto_file.h"
// #defines are a work around for <rdar://problem/8760268>
#undef __STDC_LIMIT_MACROS
#undef __STDC_CONSTANT_MACROS
#undef __STDC_LIMIT_MACROS // ld64-port
#undef __STDC_CONSTANT_MACROS // ld64-port
#define __STDC_LIMIT_MACROS 1
#define __STDC_CONSTANT_MACROS 1
#include "llvm-c/lto.h"
@ -492,7 +492,7 @@ void Parser::ltoDiagnosticHandler(lto_codegen_diagnostic_severity_t severity, co
#if LTO_API_VERSION >= 10
case LTO_DS_REMARK:
{
// PORT HACK: LLVM 3.5 prints thousands of lines about inlining, loop vectorization etc. by default
// ld64-port: LLVM 3.5 prints thousands of lines about inlining, loop vectorization etc. by default
// this is a bug (fixed in 3.6/trunk), so for LLVM 3.5, just break
static bool printremarks = ( getenv("LD64_PRINT_LTO_REMARKS") || !strstr(::lto_get_version(), "3.5") );
if ( !printremarks ) break;

View File

@ -49,7 +49,7 @@
#include "Architectures.hpp"
#include "ld.hpp"
#include "macho_relocatable_file.h"
#include "qsort_r.h"
#include "qsort_r.h" // ld64-port
extern void throwf(const char* format, ...) __attribute__ ((noreturn,format(printf, 1, 2)));
@ -2135,7 +2135,7 @@ void Parser<A>::makeSortedSectionsArray(uint32_t array[])
// sort by symbol table address
for (uint32_t i=0; i < _machOSectionsCount; ++i)
array[i] = i;
::qsort_r_local(array, _machOSectionsCount, sizeof(uint32_t), this, &sectionIndexSorter);
::qsort_r(array, _machOSectionsCount, sizeof(uint32_t), this, &sectionIndexSorter);
if ( log ) {
fprintf(stderr, "sorted sections:\n");
@ -2228,7 +2228,7 @@ void Parser<A>::makeSortedSymbolsArray(uint32_t array[], const uint32_t sectionA
// sort by symbol table address
ParserAndSectionsArray extra = { this, sectionArray };
::qsort_r_local(array, _symbolsInSections, sizeof(uint32_t), &extra, &symbolIndexSorter);
::qsort_r(array, _symbolsInSections, sizeof(uint32_t), &extra, &symbolIndexSorter);
// look for two symbols at same address
@ -4130,7 +4130,7 @@ bool CFISection<A>::needsRelocating()
template <>
void CFISection<x86_64>::cfiParse(class Parser<x86_64>& parser, uint8_t* buffer,
libunwind::CFI_Atom_Info<CFISection<x86_64>::OAS> cfiArray[],
libunwind::CFI_Atom_Info<CFISection<x86_64>::OAS> cfiArray[], // ld64-port: removed superfluous ::CFI_Atom_Info
uint32_t& count, const pint_t cuStarts[], uint32_t cuCount)
{
// copy __eh_frame data to buffer
@ -4192,7 +4192,7 @@ void CFISection<x86_64>::cfiParse(class Parser<x86_64>& parser, uint8_t* buffer,
template <>
void CFISection<x86>::cfiParse(class Parser<x86>& parser, uint8_t* buffer,
libunwind::CFI_Atom_Info<CFISection<x86>::OAS> cfiArray[],
libunwind::CFI_Atom_Info<CFISection<x86>::OAS> cfiArray[], // ld64-port: removed superfluous ::CFI_Atom_Info
uint32_t& count, const pint_t cuStarts[], uint32_t cuCount)
{
// create ObjectAddressSpace object for use by libunwind
@ -4213,7 +4213,7 @@ void CFISection<x86>::cfiParse(class Parser<x86>& parser, uint8_t* buffer,
template <>
void CFISection<arm>::cfiParse(class Parser<arm>& parser, uint8_t* buffer,
libunwind::CFI_Atom_Info<CFISection<arm>::OAS> cfiArray[],
libunwind::CFI_Atom_Info<CFISection<arm>::OAS> cfiArray[], // ld64-port: removed superfluous ::CFI_Atom_Info
uint32_t& count, const pint_t cuStarts[], uint32_t cuCount)
{
if ( !parser.armUsesZeroCostExceptions() ) {
@ -4239,7 +4239,7 @@ void CFISection<arm>::cfiParse(class Parser<arm>& parser, uint8_t* buffer,
template <>
void CFISection<arm64>::cfiParse(class Parser<arm64>& parser, uint8_t* buffer,
libunwind::CFI_Atom_Info<CFISection<arm64>::OAS> cfiArray[],
libunwind::CFI_Atom_Info<CFISection<arm64>::OAS> cfiArray[], // ld64-port: removed superfluous ::CFI_Atom_Info
uint32_t& count, const pint_t cuStarts[], uint32_t cuCount)
{
// copy __eh_frame data to buffer

View File

@ -499,7 +499,7 @@ static void makeIslandsForSection(const Options& opts, ld::Internal& state, ld::
if ( target->section().type() == ld::Section::typeStub )
dstAddr = totalTextSize;
int64_t displacement = dstAddr - srcAddr;
TargetAndOffset finalTargetAndOffset = { target, static_cast<uint32_t>(addend) };
TargetAndOffset finalTargetAndOffset = { target, static_cast<uint32_t>(addend) }; // ld64-port: addend -> static_cast<uint32_t>(addend)
const int64_t kBranchLimit = kBetweenRegions;
if ( crossSectionBranch && ((displacement > kBranchLimit) || (displacement < (-kBranchLimit))) ) {
const ld::Atom* island;