clangupc / clang-upc

Clang UPC Front-End
https://clangupc.github.io/
Other
16 stars 5 forks source link

OSX: 'upc_pgm_info': mach-o section specifier requires a segment and section separated by a comma #6

Closed swatanabe closed 11 years ago

swatanabe commented 11 years ago

On Macos/Darwin, the make fails with

fatal error: error in backend: Global variable 'GCCUPCConfig' has an invalid section specifier 'upc_pgm_info': mach-o section specifier requires a segment and section separated by a comma.

This GCCUPCConfig variable is generated by this section of code.

diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 9a55c08..895d80b 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp [...] void CodeGenModule::Release() {

Note the "setSection" call above.

This small test program indicates the expected section name syntax on a Mach OS based system.

static const char GCCUPCConfig[]

if MACH

attribute ((section("DATA,upc_pgm_info"))) __attribute ((used)) =

else

attribute ((section("upc_pgm_info"))) attribute ((used)) =

endif

"$GCCUPCConfig: (" BASE_FILE ") " "$";

int main(void) { return 0; }

I think that the lack of the ""__DATA,upc_pgm_info" syntax might be the source of the problem, but am unsure how this might be best parametrized within the compiler. Perhaps there is already some mechanism to achieve this OS dependent behavior?

swatanabe commented 11 years ago

I think the right way to solve this is to move this definition back into gcc-upc-lib.h. The only reason for the divergence from gupc is that I didn't completely understand how gupc handles it when I wrote this originally.

nenadv commented 11 years ago

I tried to push the way through this error by adding appropriate sections (__DATA) where needed. Made the following changes:

diff --git a/lib/CodeGen/CGDecl.cpp b/lib/CodeGen/CGDecl.cpp index f7c65dd..ebd7ed7 100644 --- a/lib/CodeGen/CGDecl.cpp +++ b/lib/CodeGen/CGDecl.cpp @@ -202,7 +202,11 @@ CodeGenFunction::CreateStaticVarDecl(const VarDecl &D, if (Linkage != llvm::GlobalValue::InternalLinkage) GV->setVisibility(CurFn->getVisibility()); if(SharedInit) +#if MACH

diff --git a/lib/CodeGen/CGStmtUPC.cpp b/lib/CodeGen/CGStmtUPC.cpp index 707f92b..1186d75 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"); +#if __MACH


The only change that is problematic is the one in runtime/libupc/CMakeLists.txt. I am not familiar with Cmake and don;t know how to change the include based on the system it is building on.

After this I was able to rebuild everything to the end. And did not run into the perl error. Which is interesting.

gary-funck commented 11 years ago

On 03/04/13 17:26:18, Nenad Vukicevic wrote:

I tried to push the way through this error by adding appropriate sections (__DATA) where needed. Made the following changes: [...] After this I was able to rebuild everything to the end. And did not run into the perl error. Which is interesting.

If you didn't 'make clean' or start from scratch, the .ld file might've already been created, and would be empty.

Try it from scratch, with the default -j switch.

swatanabe commented 11 years ago

Preprocessor directives aren't really the right way to handle this, as they break cross-compilation. I don't have a mac to test with, but I'll try to put something together today.

nenadv commented 11 years ago

It looks like we forgot one change that made some tests fail on Mac OS:

diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index ca5bf3a..d703484 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -458,7 +458,10 @@ void CodeGenModule::EmitUPCInits(const CtorList &Fns, const char *Globa
                              llvm::GlobalValue::AppendingLinkage,
                              llvm::ConstantArray::get(AT, Ctors),
                              GlobalName);
-    GV->setSection("upc_init_array");
+    if(isTargetDarwin())
+      GV->setSection("__DATA,upc_init_array");
+    else
+      GV->setSection("upc_init_array");
   }
 }
swatanabe commented 11 years ago

This patch looks fine. Please commit it.