3

I'm trying to compile lambda-expressions from scheme to llvm-ir and am having trouble with position independet code.

source:

(lambda (x) (display x)) 

target:

bunch of declares...
define %SObj* @G7() {
entry:
  %calltmp = call %SObj* @closure_create(i64 ptrtoint (%SObj* (%SObj*)* @G8 to i64), %SObj* null)
  ret %SObj* %calltmp
}

define %SObj* @G8(%SObj* %G6) {
entry:
  %calltmp = call %SObj* @display(%SObj* %G6)
  ret %SObj* %calltmp
}

define i32 @main(i32 %0, i8** %1) {
entry:
  %calltmp = call %SObj* @G7()
  %calltmp1 = call %SObj* @display(%SObj* %calltmp)
  ret i32 0
}

compiling this with:

llc code.ll && clang code.s -L/usr/lib -lgc -lSRuntime -o code -v

where code.ll is the printed ll-ir module gives me the error message:

/usr/bin/ld: /tmp/code-1c0b5f.o: relocation R_X86_64_32 against symbol `G8' can not be used when making a PIE object; recompile with -fPIE

Reading up on PIE doesn't quite help me solve my issue. Can someone explain me, why the ptrtoint cast in G7 causes the code to be non-PIC and how one would then implement such behaviour?

EDIT: Issue was solved by adding --relocation-model=pic to the llc call, which compiles the module

3
  • Have you recompiles with the fPIE flag as the error message suggests?
    – droptop
    May 30, 2020 at 18:37
  • Thanks! Not so easy to find, since --relocation-model is not mentionned in llc man page, only in lli's (which in cited in the 'see also' section of llc's).
    – JeanPierre
    Oct 24, 2020 at 18:11
  • I have the same error, I am new in C/C++. Where can I get info about how to use the fPIE flag? Jan 17, 2021 at 5:43

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.