Skip to content
This repository was archived by the owner on Jun 1, 2020. It is now read-only.

Commit cd25082

Browse files
committed
Adding rdynamic solves the printd problem...
Now clean up all the debugging mess!
1 parent 393a58a commit cd25082

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ $(BUILDDIR)/loop_info: $(SRC_LLVM_DIR)/experimental/loop_info.cpp
205205
$(CXX) $(CXXFLAGS) $(LLVM_CXXFLAGS) $^ $(LLVM_LDFLAGS) -o $@
206206

207207
$(BUILDDIR)/build_llvm_ir: $(SRC_LLVM_DIR)/experimental/build_llvm_ir.cpp
208-
$(CXX) $(CXXFLAGS) $(LLVM_CXXFLAGS) $^ $(LLVM_LDFLAGS) -o $@
208+
$(CXX) $(CXXFLAGS) $(LLVM_CXXFLAGS) $^ -rdynamic $(LLVM_LDFLAGS) -o $@
209209

210210
$(BUILDDIR)/remove-cstr-calls: $(SRC_CLANG_DIR)/experimental/RemoveCStrCalls.cpp
211211
$(CXX) $(CXXFLAGS) $(LLVM_CXXFLAGS) $(CLANG_INCLUDES) $^ \

src_llvm/experimental/build_llvm_ir.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
using namespace llvm;
2121

22+
// A type encapsulating simple Orc JIT functionality. Loosely based on the
23+
// KaleidoscopeJIT example in the LLVM tree. Doesn't support cross-module
24+
// symbol resolution; this JIT is best used with just a single module.
2225
class SimpleOrcJIT {
2326
public:
2427
// This sample doesn't implement on-request or lazy compilation. It therefore
@@ -34,10 +37,11 @@ class SimpleOrcJIT {
3437
SimpleOrcJIT()
3538
: TM(EngineBuilder().selectTarget()), DL(TM->createDataLayout()),
3639
CompileLayer(ObjectLayer, orc::SimpleCompiler(*TM)) {
37-
std::string s;
38-
llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr, &s);
39-
errs() << "$$ error from loading: " << s << "\n";
40-
}
40+
std::string s;
41+
bool b = llvm::sys::DynamicLibrary::LoadLibraryPermanently(nullptr, &s);
42+
errs() << "$$ LoadLibraryPermanently returned " << b
43+
<< "; error string=" << s << "\n";
44+
}
4145

4246
TargetMachine &getTargetMachine() { return *TM; }
4347

@@ -58,7 +62,7 @@ class SimpleOrcJIT {
5862
return Sym;
5963
return JITSymbol(nullptr);
6064
},
61-
[](const std::string &S) {
65+
[](const std::string &S) {
6266
errs() << "$$ external resolving " << S << "\n";
6367
return nullptr;
6468
});
@@ -152,8 +156,9 @@ Function *MakeFunction(Module *Mod, std::string name, Function *printdfunc) {
152156
}
153157

154158
/// printd - printf that takes a double prints it as "%f\n", returning 0.
155-
extern "C" void printd(double X) {
159+
extern "C" double printd(double X) {
156160
fprintf(stderr, "%f\n", X);
161+
return 0;
157162
}
158163

159164
// Signature of the function we expect.
@@ -180,6 +185,12 @@ int main(int argc, char **argv) {
180185

181186
SimpleOrcJIT JIT;
182187
Mod->setDataLayout(JIT.getTargetMachine().createDataLayout());
188+
void* s = llvm::sys::DynamicLibrary::SearchForAddressOfSymbol("printd");
189+
if (s != nullptr) {
190+
errs() << "$$ " << s << "\n";
191+
} else {
192+
errs() << "$$ SearchForAddressOfSymbol unable to find printd\n";
193+
}
183194

184195
PassManagerBuilder Builder;
185196
Builder.OptLevel = 3;

0 commit comments

Comments
 (0)