<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi,<br>
<br>
I'm using LLVM 1.8 with the GCC4-frontend on a Slackware 10.2 box (GCC
3.3.6). When issuing the following command (line 14 in a script called
manual.sh):<br>
<br>
llvm-ld -O1 *.trans -L${SOME_LIB_DIR} -L${SOME_OTHER_LIB_DIR}
-L${LLVM_FRONT}/lib -lSOME_LIB -lSOME_OTHER_LIB
-load=${MY_LIB_DIR}/opt1.so -load=${MY_LIB_DIR}/opt2.so
-debug-pass=Details -debug -o test<br>
<br>
... I get the following messages:<br>
<br>
llvm-ld: warning: Supposed library 'SOME_OTHER_LIB' isn't a library.<br>
./manual.sh: line 14: 25492 Segmentation fault<br>
<br>
When I invoke the same from within gdb, I get:<br>
<br>
[Thread debugging using libthread_db enabled]<br>
[New Thread -1210504992 (LWP 25520)]<br>
llvm-ld: warning: Supposed library 'SOME_OTHER_LIB' isn't a library.<br>
<br>
Program received signal SIGABRT, Aborted.<br>
[Switching to Thread -1210504992 (LWP 25520)]<br>
0xb7dbb027 in raise () from /lib/tls/libc.so.6<br>
<br>
... with the following backtrace:<br>
<br>
#0  0xb7dbb027 in raise () from /lib/tls/libc.so.6<br>
#1  0xb7dbc747 in abort () from /lib/tls/libc.so.6<br>
#2  0xb7eb6721 in uw_init_context_1 () from
${LLVM_FRONT}/lib/libgcc_s.so.1<br>
#3  0xbf9fd140 in ?? ()<br>
#4  0xbf9fcf20 in ?? ()<br>
#5  0x00000064 in ?? ()<br>
#6  0x082a02cd in llvm::Optimize (M=0x85bf330) at
${LLVM_SRC}/tools/llvm-ld/Optimize.cpp:180<br>
#7  0x082a7161 in main (argc=17, argv=0xbf9fd454, envp=0xbf9fd49c) at
${LLVM_SRC}/tools/llvm-ld/llvm-ld.cpp:467<br>
<br>
The exception raised apparently was not caused by the first warning
message, but resulted from the following snippet of
${LLVM_SRC}/tools/llvm-ld/Optimize.cpp (near line 180):<br>
<br>
std::vector<std::string> plugins = LoadableModules;<br>
for (std::vector<std::string>::iterator I = plugins.begin(), E =
plugins.end(); I != E; ++I) {<br>
    sys::DynamicLibrary dll(I->c_str());<br>
    typedef void (*OptimizeFunc)(PassManager&,int);<br>
    OptimizeFunc OF = OptimizeFunc(<br>
        (intptr_t)dll.GetAddressOfSymbol("RunOptimizations"));<br>
    if (OF == 0) {<br>
      throw std::string("Optimization Module '") + *I +<br>
        "' is missing the RunOptimizations symbol";<br>
    }<br>
    (*OF)(Passes,OptLevel);<br>
}<br>
<br>
The RunOptimizations-symbol is only mentioned briefly in the manual of
llvm-ld:<br>
<br>
-load module<br>
<dl>
  <dd>Load an optimization module, <em>module</em>, which is expected
to be a dynamic
library that provides the function name <code>RunOptimizations</code>.
This function will
be passed the PassManager, and the optimization level (values 0-5 based
on the
    <strong>-On</strong> option). This function may add passes to the
PassManager that should be
run. This feature allows the optimization passes of <strong>llvm-ld</strong>
to be extended.</dd>
</dl>
Now, here are my two questions (finally ;-)) :<br>
<ul>
  <li>Why is SOME_OTHER_LIB not a library from llvm-ld's point of view?
It's supposed to be a shared library needed by opt1.so (my first
optimization pass), and NOT by the source files which are processed.
Should I pass it in some other way than by -lSOME_OTHER_LIB? Should/Can
I pass it in the first place?</li>
  <li>What's the meaning of RunOptimizations? This name is only
mentioned in the code snippet above and in the llvm-ld docs, but
nowhere else. Both opt1.so and opt2.so do show up using opt, so it
seems there is some incompatibility between opt and llvm-ld. llvm-link
apparently offers no alternative.<br>
  </li>
</ul>
Kind regards,<br>
<br>
Bram Adams<br>
GH-SEL, INTEC, Ghent University (Belgium)<br>
</body>
</html>