Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llvmlite.binding.TargetMachine.emit_object() emits unknown object format on Windows #1052

Open
OffensiverHase opened this issue May 25, 2024 · 2 comments

Comments

@OffensiverHase
Copy link

Hi, I am trying to create an AOT compiled language with llvmlite and I'm trying to get an object file and then link it via gcc, but gcc gives me the following error when running gcc main_temp.o -o main:

main_temp.o: file not recognized: File format not recognized
collect2.exe: error: ld returned 1 exit status

I have seen that a similar question has been asked here, but I tried the solutions given there and they didn't work.

My code looks like this:

import llvmlite.binding as llvm

OUTPUT = 'main'

target = llvm.Target.from_triple(module.triple)  # 'x86_64-pc-windows-msvc'
target_machine = target.create_target_machine(codemodel='default')

with open(OUTPUT + '_temp.o', 'wb') as f:
    f.write(target_machine.emit_object(llvm_module))
subprocess.run(['gcc', OUTPUT + '_temp.o', '-o', OUTPUT], capture_output=True, text=True)
os.remove(OUTPUT + '_temp.o')

objdump -a main_temp.o also fails: objdump: main_temp.o: File format not recognized
Thanks in advance

@sklam
Copy link
Member

sklam commented May 28, 2024

I am not certain but the -msvc should cause LLVM to produce COFF but does gcc accept that? Is this the inverse problem that you need -elf for gcc to work?

@OffensiverHase
Copy link
Author

Sorry, but I cannot follow you. What do I have to do to get a .exe file? I thought elf is only for linux?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants