[pkg-d-commits] [ldc] 192/211: Revert "Shared library support for OS X (#1705)"
Matthias Klumpp
mak at moszumanska.debian.org
Sun Apr 23 22:36:22 UTC 2017
This is an automated email from the git hooks/post-receive script.
mak pushed a commit to annotated tag v1.1.0
in repository ldc.
commit 32c475d19eabe1cf9b2d1790d432c87201829aff
Author: Martin <noone at nowhere.com>
Date: Fri Nov 18 22:01:48 2016 +0100
Revert "Shared library support for OS X (#1705)"
This reverts commit bb2b648d8e286c82cc55219a2d2ac067e361d432.
---
.travis.yml | 3 -
gen/modules.cpp | 201 ++++++++++++++------------------------------
gen/runtime.cpp | 39 ++++++---
runtime/CMakeLists.txt | 12 ++-
runtime/druntime | 2 +-
tests/codegen/llvm_used_1.d | 4 +-
6 files changed, 96 insertions(+), 165 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 5d9f69d..5e9a825 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -21,9 +21,6 @@ matrix:
- os: osx
d: ldc
env: LLVM_VERSION=3.9.0
- - os: osx
- d: ldc
- env: LLVM_VERSION=3.9.0 OPTS="-DBUILD_SHARED_LIBS=ON"
allow_failures:
#- env: LLVM_VERSION=3.9
diff --git a/gen/modules.cpp b/gen/modules.cpp
index c38482e..d070c4b 100644
--- a/gen/modules.cpp
+++ b/gen/modules.cpp
@@ -95,52 +95,9 @@ void Module::makeObjectFilenameUnique() {
}
namespace {
-/// Ways the druntime module registry system can be implemented.
-enum class RegistryStyle {
- /// Modules are inserted into a linked list starting at the _Dmodule_ref
- /// global.
- legacyLinkedList,
-
- /// Module references are emitted into the .minfo section. Global
- /// constructors/destructors make sure _d_dso_registry is invoked once per ELF
- /// object.
- sectionELF,
-
- /// Module references are emitted into the .minfo section. Global
- /// constructors/destructors make sure _d_dso_registry is invoked once per
- /// shared object. A "TLS anchor" function to identify the TLS range
- /// corresponding to this image is also passed to druntime.
- sectionDarwin
-};
-
-/// Returns the module registry style to use for the current target triple.
-RegistryStyle getModuleRegistryStyle() {
- const auto t = global.params.targetTriple;
-
- if (t->isMacOSX()) {
- return RegistryStyle::sectionDarwin;
- }
-
- if ((t->isOSLinux() && t->getEnvironment() != llvm::Triple::Android) ||
- t->isOSFreeBSD() ||
-#if LDC_LLVM_VER > 305
- t->isOSNetBSD() || t->isOSOpenBSD() || t->isOSDragonFly()
-#else
- t->getOS() == llvm::Triple::NetBSD ||
- t->getOS() == llvm::Triple::OpenBSD ||
- t->getOS() == llvm::Triple::DragonFly
-#endif
- ) {
- return RegistryStyle::sectionELF;
- }
- return RegistryStyle::legacyLinkedList;
-}
-
-/// Build ModuleReference and register function, to register the module info in
-/// the global linked list.
-///
-/// Implements getModuleRegistryStyle() == RegistryStyle::legacyLinkedList.
+// build ModuleReference and register function, to register the module info in
+// the global linked list
LLFunction *build_module_reference_and_ctor(const char *moduleMangle,
LLConstant *moduleinfo) {
// build ctor type
@@ -213,49 +170,17 @@ LLFunction *build_module_reference_and_ctor(const char *moduleMangle,
return ctor;
}
-/// Builds a void*() function with hidden visibility that returns the address of
-/// a dummy TLS global (also with hidden visibility).
-///
-/// The global is non-zero-initialised and aligned to 16 bytes.
-llvm::Function *buildGetTLSAnchor() {
- // Create a dummmy TLS global private to this module.
- const auto one =
- llvm::ConstantInt::get(llvm::Type::getInt8Ty(gIR->context()), 1);
- const auto anchor = getOrCreateGlobal(
- Loc(), gIR->module, one->getType(), false,
- llvm::GlobalValue::LinkOnceODRLinkage, one, "ldc.tls_anchor", true);
- anchor->setVisibility(llvm::GlobalValue::HiddenVisibility);
- anchor->setAlignment(16);
-
- const auto getAnchor =
- llvm::Function::Create(llvm::FunctionType::get(getVoidPtrType(), false),
- llvm::GlobalValue::LinkOnceODRLinkage,
- "ldc.get_tls_anchor", &gIR->module);
- getAnchor->setVisibility(llvm::GlobalValue::HiddenVisibility);
-
- IRBuilder<> builder(llvm::BasicBlock::Create(gIR->context(), "", getAnchor));
- builder.CreateRet(anchor);
-
- return getAnchor;
-}
-
-/// Builds the ldc.register_dso function, which is called by the global
-/// {c, d}tors to invoke _d_dso_registry.
+/// Builds the body for the ldc.dso_ctor and ldc.dso_dtor functions.
///
/// Pseudocode:
/// void ldc.register_dso(bool isShutdown, void* minfoUsedPointer) {
/// if (dsoInitialized == isShutdown) {
/// dsoInitialized = !isShutdown;
-/// auto record = {1, dsoSlot, minfoBeg, minfoEnd[, getTlsAnchor],
-/// minfoUsedPointer};
+/// auto record = {1, dsoSlot, minfoBeg, minfoEnd, minfoUsedPointer};
/// _d_dso_registry(cast(CompilerDSOData*)&record);
/// }
/// }
-///
-/// On Darwin platforms, the record contains an extra pointer to a function
-/// which returns the address of a TLS global.
-llvm::Function *buildRegisterDSO(RegistryStyle style,
- llvm::Value *dsoInitialized,
+llvm::Function *buildRegisterDSO(llvm::Value *dsoInitialized,
llvm::Value *dsoSlot, llvm::Value *minfoBeg,
llvm::Value *minfoEnd) {
llvm::Type *argTypes[] = {llvm::Type::getInt1Ty(gIR->context()),
@@ -281,11 +206,6 @@ llvm::Function *buildRegisterDSO(RegistryStyle style,
getRuntimeFunction(Loc(), gIR->module, "_d_dso_registry");
const auto recordPtrTy = dsoRegistry->getFunctionType()->getContainedType(1);
- llvm::Function *getTlsAnchorPtr;
- if (style == RegistryStyle::sectionDarwin) {
- getTlsAnchorPtr = buildGetTLSAnchor();
- }
-
const auto entryBB = llvm::BasicBlock::Create(gIR->context(), "", fn);
const auto initBB = llvm::BasicBlock::Create(gIR->context(), "init", fn);
const auto endBB = llvm::BasicBlock::Create(gIR->context(), "end", fn);
@@ -303,38 +223,24 @@ llvm::Function *buildRegisterDSO(RegistryStyle style,
b.CreateStore(b.CreateZExt(newFlag, b.getInt8Ty()), dsoInitialized);
llvm::Constant *version = DtoConstSize_t(1);
- llvm::SmallVector<llvm::Type *, 6> memberTypes;
- memberTypes.push_back(version->getType());
- memberTypes.push_back(dsoSlot->getType());
- memberTypes.push_back(minfoBeg->getType());
- memberTypes.push_back(minfoEnd->getType());
- if (style == RegistryStyle::sectionDarwin) {
- memberTypes.push_back(getTlsAnchorPtr->getType());
- }
- memberTypes.push_back(minfoUsedPointer->getType());
+ llvm::Type *memberTypes[] = {version->getType(), dsoSlot->getType(),
+ minfoBeg->getType(), minfoEnd->getType(),
+ minfoUsedPointer->getType()};
llvm::StructType *stype =
llvm::StructType::get(gIR->context(), memberTypes, false);
llvm::Value *record = b.CreateAlloca(stype);
-
- unsigned i = 0;
#if LDC_LLVM_VER >= 307
- b.CreateStore(version, b.CreateStructGEP(stype, record, i++));
- b.CreateStore(dsoSlot, b.CreateStructGEP(stype, record, i++));
- b.CreateStore(minfoBeg, b.CreateStructGEP(stype, record, i++));
- b.CreateStore(minfoEnd, b.CreateStructGEP(stype, record, i++));
- if (style == RegistryStyle::sectionDarwin) {
- b.CreateStore(getTlsAnchorPtr, b.CreateStructGEP(stype, record, i++));
- }
- b.CreateStore(minfoUsedPointer, b.CreateStructGEP(stype, record, i++));
+ b.CreateStore(version, b.CreateStructGEP(stype, record, 0)); // version
+ b.CreateStore(dsoSlot, b.CreateStructGEP(stype, record, 1)); // slot
+ b.CreateStore(minfoBeg, b.CreateStructGEP(stype, record, 2));
+ b.CreateStore(minfoEnd, b.CreateStructGEP(stype, record, 3));
+ b.CreateStore(minfoUsedPointer, b.CreateStructGEP(stype, record, 4));
#else
- b.CreateStore(version, b.CreateStructGEP(record, i++));
- b.CreateStore(dsoSlot, b.CreateStructGEP(record, i++));
- b.CreateStore(minfoBeg, b.CreateStructGEP(record, i++));
- b.CreateStore(minfoEnd, b.CreateStructGEP(record, i++));
- if (style == RegistryStyle::sectionDarwin) {
- b.CreateStore(getTlsAnchorPtr, b.CreateStructGEP(record, i++));
- }
- b.CreateStore(minfoUsedPointer, b.CreateStructGEP(record, i++));
+ b.CreateStore(version, b.CreateStructGEP(record, 0)); // version
+ b.CreateStore(dsoSlot, b.CreateStructGEP(record, 1)); // slot
+ b.CreateStore(minfoBeg, b.CreateStructGEP(record, 2));
+ b.CreateStore(minfoEnd, b.CreateStructGEP(record, 3));
+ b.CreateStore(minfoUsedPointer, b.CreateStructGEP(record, 4));
#endif
b.CreateCall(dsoRegistry, b.CreateBitCast(record, recordPtrTy));
@@ -348,10 +254,8 @@ llvm::Function *buildRegisterDSO(RegistryStyle style,
return fn;
}
-void emitModuleRefToSection(RegistryStyle style, std::string moduleMangle,
- llvm::Constant *thisModuleInfo) {
- assert(style == RegistryStyle::sectionELF ||
- style == RegistryStyle::sectionDarwin);
+void build_module_ref(std::string moduleMangle,
+ llvm::Constant *thisModuleInfo) {
// Only for the first D module to be emitted into this llvm::Module we need to
// create the global ctors/dtors. The magic linker symbols used to get the
// start and end of the .minfo section also only need to be emitted for the
@@ -364,6 +268,20 @@ void emitModuleRefToSection(RegistryStyle style, std::string moduleMangle,
llvm::Type *const moduleInfoPtrTy = DtoPtrToType(Module::moduleinfo->type);
+ // Order is important here: We must create the symbols in the
+ // bracketing sections right before/after the ModuleInfo reference
+ // so that they end up in the correct order in the object file.
+ llvm::GlobalVariable *minfoBeg;
+ if (isFirst) {
+ minfoBeg = new llvm::GlobalVariable(
+ gIR->module, moduleInfoPtrTy,
+ false, // FIXME: mRelocModel != llvm::Reloc::PIC_
+ llvm::GlobalValue::LinkOnceODRLinkage, getNullPtr(moduleInfoPtrTy),
+ "_minfo_beg");
+ minfoBeg->setSection(".minfo_beg");
+ minfoBeg->setVisibility(llvm::GlobalValue::HiddenVisibility);
+ }
+
std::string thismrefname = "_D";
thismrefname += moduleMangle;
thismrefname += "11__moduleRefZ";
@@ -372,8 +290,7 @@ void emitModuleRefToSection(RegistryStyle style, std::string moduleMangle,
false, // FIXME: mRelocModel != llvm::Reloc::PIC_
llvm::GlobalValue::LinkOnceODRLinkage,
DtoBitCast(thisModuleInfo, moduleInfoPtrTy), thismrefname);
- thismref->setSection((style == RegistryStyle::sectionDarwin) ? "__DATA,.minfo"
- : "__minfo");
+ thismref->setSection(".minfo");
gIR->usedArray.push_back(thismref);
if (!isFirst) {
@@ -381,21 +298,12 @@ void emitModuleRefToSection(RegistryStyle style, std::string moduleMangle,
return;
}
- // Use magic linker symbol names to obtain the begin and end of the .minfo
- // section.
- const auto magicBeginSymbolName = (style == RegistryStyle::sectionDarwin)
- ? "\1section$start$__DATA$.minfo"
- : "__start___minfo";
- const auto magicEndSymbolName = (style == RegistryStyle::sectionDarwin)
- ? "\1section$end$__DATA$.minfo"
- : "__stop___minfo";
- auto minfoBeg = new llvm::GlobalVariable(gIR->module, moduleInfoPtrTy, false,
- llvm::GlobalValue::ExternalLinkage,
- nullptr, magicBeginSymbolName);
- auto minfoEnd = new llvm::GlobalVariable(gIR->module, moduleInfoPtrTy, false,
- llvm::GlobalValue::ExternalLinkage,
- nullptr, magicEndSymbolName);
- minfoBeg->setVisibility(llvm::GlobalValue::HiddenVisibility);
+ auto minfoEnd =
+ new llvm::GlobalVariable(gIR->module, moduleInfoPtrTy,
+ false, // FIXME: mRelocModel != llvm::Reloc::PIC_
+ llvm::GlobalValue::LinkOnceODRLinkage,
+ getNullPtr(moduleInfoPtrTy), "_minfo_end");
+ minfoEnd->setSection(".minfo_end");
minfoEnd->setVisibility(llvm::GlobalValue::HiddenVisibility);
// Build the ctor to invoke _d_dso_registry.
@@ -451,7 +359,7 @@ void emitModuleRefToSection(RegistryStyle style, std::string moduleMangle,
llvm::Value *minfoRefPtr = DtoBitCast(thismref, getVoidPtrType());
const auto registerDSO =
- buildRegisterDSO(style, dsoInitialized, dsoSlot, minfoBeg, minfoEnd);
+ buildRegisterDSO(dsoInitialized, dsoSlot, minfoBeg, minfoEnd);
std::string ctorName = "ldc.dso_ctor.";
ctorName += moduleMangle;
@@ -679,13 +587,26 @@ void loadInstrProfileData(IRState *irs) {
void registerModuleInfo(Module *m) {
const auto moduleInfoSym = genModuleInfo(m);
- const auto style = getModuleRegistryStyle();
- if (style == RegistryStyle::legacyLinkedList) {
- const auto miCtor =
- build_module_reference_and_ctor(mangle(m), moduleInfoSym);
- AppendFunctionToLLVMGlobalCtorsDtors(miCtor, 65535, true);
+
+ if ((global.params.targetTriple->isOSLinux() &&
+ global.params.targetTriple->getEnvironment() != llvm::Triple::Android) ||
+ global.params.targetTriple->isOSFreeBSD() ||
+#if LDC_LLVM_VER > 305
+ global.params.targetTriple->isOSNetBSD() ||
+ global.params.targetTriple->isOSOpenBSD() ||
+ global.params.targetTriple->isOSDragonFly()
+#else
+ global.params.targetTriple->getOS() == llvm::Triple::NetBSD ||
+ global.params.targetTriple->getOS() == llvm::Triple::OpenBSD ||
+ global.params.targetTriple->getOS() == llvm::Triple::DragonFly
+#endif
+ ) {
+ build_module_ref(mangle(m), moduleInfoSym);
} else {
- emitModuleRefToSection(style, mangle(m), moduleInfoSym);
+ // build the modulereference and ctor for registering it
+ LLFunction *mictor =
+ build_module_reference_and_ctor(mangle(m), moduleInfoSym);
+ AppendFunctionToLLVMGlobalCtorsDtors(mictor, 65535, true);
}
}
}
diff --git a/gen/runtime.cpp b/gen/runtime.cpp
index 6554481..cf86cf4 100644
--- a/gen/runtime.cpp
+++ b/gen/runtime.cpp
@@ -695,14 +695,29 @@ static void buildRuntimeModule() {
//////////////////////////////////////////////////////////////////////////////
// void invariant._d_invariant(Object o)
- createFwdDecl(LINKd, voidTy,
- {gABI->mangleFunctionForLLVM(
- "_D9invariant12_d_invariantFC6ObjectZv", LINKd)},
- {objectTy});
+ createFwdDecl(
+ LINKd, voidTy,
+ {gABI->mangleFunctionForLLVM("_D9invariant12_d_invariantFC6ObjectZv", LINKd)},
+ {objectTy});
+
+ // void _d_dso_registry(CompilerDSOData* data)
+ llvm::StringRef fname("_d_dso_registry");
+
+ LLType *LLvoidTy = LLType::getVoidTy(gIR->context());
+ LLType *LLvoidPtrPtrTy = getPtrToType(getPtrToType(LLvoidTy));
+ LLType *moduleInfoPtrPtrTy =
+ getPtrToType(getPtrToType(DtoType(Module::moduleinfo->type)));
+
+ llvm::StructType *dsoDataTy =
+ llvm::StructType::get(DtoSize_t(), // version
+ LLvoidPtrPtrTy, // slot
+ moduleInfoPtrPtrTy, // _minfo_beg
+ moduleInfoPtrPtrTy, // _minfo_end
+ NULL);
- // void _d_dso_registry(void* data)
- // (the argument is really a pointer to rt.sections_elf_shared.CompilerDSOData)
- createFwdDecl(LINKc, voidTy, {"_d_dso_registry"}, {voidPtrTy});
+ llvm::Type *types[] = {getPtrToType(dsoDataTy)};
+ llvm::FunctionType *fty = llvm::FunctionType::get(LLvoidTy, types, false);
+ llvm::Function::Create(fty, llvm::GlobalValue::ExternalLinkage, fname, M);
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
@@ -720,9 +735,9 @@ static void buildRuntimeModule() {
// The types of these functions don't really matter because they are always
// bitcast to correct signature before calling.
- Type *objectPtrTy = voidPtrTy;
- Type *selectorPtrTy = voidPtrTy;
- Type *realTy = Type::tfloat80;
+ Type* objectPtrTy = voidPtrTy;
+ Type* selectorPtrTy = voidPtrTy;
+ Type* realTy = Type::tfloat80;
// id objc_msgSend(id self, SEL op, ...)
// Function called early and/or often, so lazy binding isn't worthwhile.
@@ -735,13 +750,13 @@ static void buildRuntimeModule() {
// creal objc_msgSend_fp2ret(id self, SEL op, ...)
createFwdDecl(LINKc, Type::tcomplex80, {"objc_msgSend_fp2ret"},
{objectPtrTy, selectorPtrTy});
- // fall-thru
+ // fall-thru
case llvm::Triple::x86:
// x86_64 real return only, x86 float, double, real return
// real objc_msgSend_fpret(id self, SEL op, ...)
createFwdDecl(LINKc, realTy, {"objc_msgSend_fpret"},
{objectPtrTy, selectorPtrTy});
- // fall-thru
+ // fall-thru
case llvm::Triple::arm:
case llvm::Triple::thumb:
// used when return value is aggregate via a hidden sret arg
diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt
index d4c6838..ff9da8f 100644
--- a/runtime/CMakeLists.txt
+++ b/runtime/CMakeLists.txt
@@ -32,10 +32,8 @@ else()
endif()
if(BUILD_SHARED_LIBS)
- if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND
- NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD" AND
- NOT APPLE)
- message(FATAL_ERROR "Shared libraries (BUILD_SHARED_LIBS) are only supported on Linux, macOS and FreeBSD for the time being.")
+ if(NOT ${CMAKE_SYSTEM_NAME} MATCHES "Linux" AND NOT ${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
+ message(FATAL_ERROR "Shared libraries (BUILD_SHARED_LIBS) are only supported on Linux and FreeBSD for the time being.")
endif()
list(APPEND D_FLAGS -relocation-model=pic)
@@ -419,10 +417,10 @@ macro(build_runtime d_flags c_flags ld_flags lib_suffix path_suffix outlist_targ
# C executables.
if(BUILD_SHARED_LIBS)
- if(${CMAKE_SYSTEM} MATCHES "Linux")
- set(dso_system_libs "m" "pthread" "rt" "dl")
- else()
+ if(${CMAKE_SYSTEM} MATCHES "FreeBSD")
set(dso_system_libs "m" "pthread")
+ else()
+ set(dso_system_libs "m" "pthread" "rt" "dl")
endif()
target_link_libraries(druntime-ldc${target_suffix} ${dso_system_libs})
endif()
diff --git a/runtime/druntime b/runtime/druntime
index 1fa60c4..e336b51 160000
--- a/runtime/druntime
+++ b/runtime/druntime
@@ -1 +1 @@
-Subproject commit 1fa60c4f5516e63a5050255c5757f48c31273ec3
+Subproject commit e336b5136f223567f40a8a4a01d5b5b87ce88f83
diff --git a/tests/codegen/llvm_used_1.d b/tests/codegen/llvm_used_1.d
index 31fae6d..a23045a 100644
--- a/tests/codegen/llvm_used_1.d
+++ b/tests/codegen/llvm_used_1.d
@@ -1,7 +1,7 @@
// Test that llvm.used is emitted correctly when multiple D modules are compiled into one LLVM module.
-// Explicitly use OS X triple, so that llvm.used is used for moduleinfo globals.
-// RUN: %ldc -c -output-ll -O3 %S/inputs/module_ctor.d %s -of=%t.ll -mtriple=x86_64-apple-macosx && FileCheck --check-prefix=LLVM %s < %t.ll
+// Explicitly use a Linux triple, so that llvm.used is used for moduleinfo globals.
+// RUN: %ldc -c -output-ll -O3 %S/inputs/module_ctor.d %s -of=%t.ll -mtriple=x86_64-pc-linux-gnu && FileCheck --check-prefix=LLVM %s < %t.ll
// RUN: %ldc -O3 %S/inputs/module_ctor.d -run %s | FileCheck --check-prefix=EXECUTE %s
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git
More information about the pkg-d-commits
mailing list