From 3a4e2565060f47c39e3a3169d304c7c503796cb6 Mon Sep 17 00:00:00 2001 From: Steven Watanabe Date: Tue, 5 Mar 2013 11:53:10 -0800 Subject: [PATCH] Fix section names for OSX. Fixes #6. --- lib/CodeGen/CGDecl.cpp | 8 ++++++-- lib/CodeGen/CGStmtUPC.cpp | 6 +++++- lib/CodeGen/CodeGenModule.cpp | 13 ++++++++++--- runtime/libupc/CMakeLists.txt | 8 +++++++- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index f7c65dd76f4b..5b1b9a0284a7 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -201,8 +201,12 @@ CodeGenFunction::CreateStaticVarDecl(const VarDecl &D, GV->setAlignment(getContext().getDeclAlign(&D).getQuantity()); if (Linkage != llvm::GlobalValue::InternalLinkage) GV->setVisibility(CurFn->getVisibility()); - if(SharedInit) - GV->setSection("upc_shared"); + if(SharedInit) { + if(CGM.isTargetDarwin()) + GV->setSection("__DATA,upc_shared"); + else + GV->setSection("upc_shared"); + } return GV; } diff --git a/lib/CodeGen/CGStmtUPC.cpp b/lib/CodeGen/CGStmtUPC.cpp index 707f92b6dbea..9db0c81096d6 100644 --- a/lib/CodeGen/CGStmtUPC.cpp +++ b/lib/CodeGen/CGStmtUPC.cpp @@ -68,7 +68,11 @@ llvm::Constant *CodeGenModule::getUPCFenceVar() { llvm::GlobalValue::LinkOnceODRLinkage, llvm::ConstantInt::get(IntTy, 0), "__upc_fence_var"); - GV->setSection("upc_shared"); + + if(isTargetDarwin()) + GV->setSection("__DATA,upc_shared"); + else + GV->setSection("upc_shared"); UPCFenceVar = GV; } return UPCFenceVar; diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 895d80b10eed..ca5bf3a89f58 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -168,7 +168,10 @@ void CodeGenModule::Release() { true, llvm::GlobalValue::InternalLinkage, llvm::ConstantDataArray::getString(getLLVMContext(), str), "GCCUPCConfig"); - conf->setSection("upc_pgm_info"); + if(isTargetDarwin()) + conf->setSection("__DATA,upc_pgm_info"); + else + conf->setSection("upc_pgm_info"); AddUsedGlobal(conf); } EmitDeferred(); @@ -1654,8 +1657,12 @@ void CodeGenModule::EmitGlobalVarDefinition(const VarDecl *D) { GV->setConstant(false); SetCommonAttributes(D, GV); - if(ASTTy.getQualifiers().hasShared()) - GV->setSection("upc_shared"); + if(ASTTy.getQualifiers().hasShared()) { + if(isTargetDarwin()) + GV->setSection("__DATA,upc_shared"); + else + GV->setSection("upc_shared"); + } // Emit the initializer function if necessary. if (NeedsGlobalCtor || NeedsGlobalDtor) diff --git a/runtime/libupc/CMakeLists.txt b/runtime/libupc/CMakeLists.txt index fb9362887a80..275e32d1565e 100644 --- a/runtime/libupc/CMakeLists.txt +++ b/runtime/libupc/CMakeLists.txt @@ -442,12 +442,18 @@ endforeach() set_property(SOURCE ${LIBUPC_SOURCES} PROPERTY LANGUAGE C) +if(APPLE) + set(config_dir darwin) +else() + set(config_dir default) +endif() + macro(add_crt_target name opts) set(obj ${LLVM_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/${name}.o) list(APPEND objects ${obj}) add_custom_target(${name} ALL DEPENDS ${obj}) add_custom_command(OUTPUT ${obj} - COMMAND ${CMAKE_C_COMPILER} -c -o ${obj} ${PROJECT_SOURCE_DIR}/upc-crtstuff.c -I${PROJECT_SOURCE_DIR}/config/default -I${PROJECT_BINARY_DIR} ${opts} + COMMAND ${CMAKE_C_COMPILER} -c -o ${obj} ${PROJECT_SOURCE_DIR}/upc-crtstuff.c -I${PROJECT_SOURCE_DIR}/config/${config_dir} -I${PROJECT_BINARY_DIR} ${opts} MAIN_DEPENDENCY upc-crtstuff.c IMPLICIT_DEPENDENCY upc-crtstuff.c VERBATIM)