A potential bug in ISPC when linking ispc and non-ispc modules w/ debug enabled

154 views
Skip to first unread message

Vishal Sharma

unread,
Mar 11, 2015, 12:09:48 PM3/11/15
to ispc...@googlegroups.com
Hi ISPC developers,

I am trying to link two bitcode files using llvm-link. Both the bitcode files are generated with debug flag enabled (-g option).  The first bitcode file is generated using clang++ with a regular cpp file while the second bitcode file is generated using ispc --emit-llvm flag. Below are the sample commands.

 $ clang++ foo_nonispc.cpp -emit-llvm -g -c -o foo_nonispc.bc
 $ ispc ao.ispc -o ao_ispc.bc --emit-llvm -g
 $ llvm-link foo_nonispc.bc ao_ispc.bc -o result.bc

 When trying to run the third command, it fails with follow error message:
 Error: llvm-link: link error in 'ao_ispc.bc': linking module flags 'Debug Info Version': IDs have conflicting behavior

 Debugging it further I could narrow down the offended code in the LLVM source code (release_35 branch) located at: LLVM_SRC/lib/Linker/LinkModules.cpp: 1318 (code snippet mentioned below for easy reference)

  // Diagnose inconsistent merge behavior types.
    if (SrcBehaviorValue != DstBehaviorValue) {
      MDString *DestID = cast<MDString>(DstOp->getOperand(1));
      HasErr |= emitError("linking module flags '" + ID->getString() +
                          "': IDs have conflicting behaviors");
      continue;
    }

  After further debugging, I noticed that there is a mismatch in the value of the "behaviour" set for the same "flag ID": Debug Info Version
  ISPC sets the flag value as 2 (i.e. Warning) whereas LLVM set it as 1 (i.e. Error)..

  Going through the LLVM doc (http://llvm.org/docs/LangRef.html#module-flags-metadata), it seems that we can't define/set different behaviours for the same flag ID in two or more different modules. Below is the relevant excerpt:

 "It is an error for a particular unique flag ID to have multiple behaviors, except in the case of Require (which adds restrictions on another metadata value) or Override."

 Therefore, I think we just require a minor fix in ISPC where the  behaviour for "Debug Info Version" flag should be set to 1 instead of 2 to make it consistent with LLVM.

 Your thoughts? Thanks for your help!
 
 Vishal

Vishal Sharma

unread,
Mar 11, 2015, 1:20:42 PM3/11/15
to ispc...@googlegroups.com
Clarification: In case this is useful, I am using LLVM3.5 and installed it using alloy.py script which also applied the necessary llvm patches...

--
You received this message because you are subscribed to the Google Groups "Intel SPMD Program Compiler Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ispc-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanks
Vishal

Dmitry Babokin

unread,
Mar 11, 2015, 1:41:30 PM3/11/15
to ispc...@googlegroups.com
You are on Linux and using ispc v.1.8.1, right?

Vishal Sharma

unread,
Mar 11, 2015, 1:45:15 PM3/11/15
to ispc...@googlegroups.com
Yes, Ubuntu 12.04. I think ISPC version is 1.8.2dev (may be I did "git pull" recently). Is it causing the problem? thanks!

$ ispc --version
$ Intel(r) SPMD Program Compiler (ispc), 1.8.2dev (build commit dfcdd84dc60488d6 @ 20150307, LLVM 3.5)

Vishal Sharma

unread,
Mar 11, 2015, 1:50:52 PM3/11/15
to ispc...@googlegroups.com
Btw, I've put a workaround in the LinkModules.cpp to skip the behavior value check for the flag ID "Debug Info Version".. With this w/a, I am able to do the linking successfully! However, it will be great to get this fixed in case you think this is a bug. thanks!
--
Thanks
Vishal

Dmitry Babokin

unread,
Mar 11, 2015, 2:24:38 PM3/11/15
to ispc...@googlegroups.com
I see, you are building trunk, that's even better.

I don't see a problem changing this flag in ISPC, but I don't really understand the consequences. Though I think it should be fine. I'll ask someone in our team to run tests and see if it breaks something.

Vishal Sharma

unread,
Mar 11, 2015, 2:27:49 PM3/11/15
to ispc...@googlegroups.com
Great, thanks!

I can also verify from my side once the fix is released...

Dmitry Babokin

unread,
Mar 12, 2015, 10:22:56 AM3/12/15
to ispc...@googlegroups.com
I've merged the fix. Please give it a try and let me know if it fixed the problem.

Vishal Sharma

unread,
Mar 12, 2015, 10:42:46 AM3/12/15
to ispc...@googlegroups.com
Hi Dmitry,

Thanks for the quick turnaround! With the latest changes, the bug is fixed!

Vishal

Dmitry Babokin

unread,
Mar 12, 2015, 2:29:12 PM3/12/15
to ispc...@googlegroups.com
Thanks for verifying this!
Reply all
Reply to author
Forward
0 new messages