-
Notifications
You must be signed in to change notification settings - Fork 34
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
Cannot do cross-compilation? (--target flag not recognized) #71
Comments
I suspect it needs a source modification, specifically in Line 159 in 49c0709
That function is aware of a bunch of flags; it probably needs to be made aware of |
That's what i thought as well, I am unfamiliar with the codebase though, and I am not sure which callback i should assign it to: it might be |
I'd trial and error it 🙂 -- |
Yes my guess is that it is both compile and link. If you do fix it, can you please make a pull request? |
Yes, I'm planning to have a look at it today, if I'm successful you'll find a pull request 😄 |
EDIT: Just found a workaround, see next message Hello, I made the modification in this commit. I added the following code: "-target": {1, pr.compileLinkBinaryCallback}, Note: the flag is It is almost there, meaning that an aarch64 ELF executable is created, but no gclang -target aarch64-linux-gnu /tmp/prova/a.c
# outputs:
objcopy: Unable to recognise the format of the input file `.a.c.o'
WARNING:attachBitcodePathToObject: objcopy [--add-section .llvm_bc=/tmp/gllvm3259057631 .a.c.o] failed because exit status 1 You can see that a warning is printed. The
But it won't contain the get-bc a.out
ERROR:Error reading the .llvm_bc section of ELF file a.out. it is verifiable independently via readelf -S a.out | grep .llvm_bc # no output I suspect that the |
Just found out that for some reason, In order to get proper cross-compilation to work end-to-end, i need to set the environment variable So this works on my fork: GLLVM_OBJCOPY=llvm-objcopy gclang -target aarch64-linux-gnu a.c If for some reason you want to use the GNU GLLVM_OBJCOPY=aarch64-linux-gnu-objcopy gclang -target aarch64-linux-gnu a.c I found out that the decision is carried in if runtime.GOOS == osDARWIN {
if len(LLVMLd) > 0 {
attachCmd = LLVMLd
} else {
attachCmd = "ld"
}
attachCmdArgs = []string{"-r", "-keep_private_externs", objFile, "-sectcreate", DarwinSegmentName, DarwinSectionName, tmpFile.Name(), "-o", objFile}
} else {
if len(LLVMObjcopy) > 0 {
attachCmd = LLVMObjcopy
} else {
attachCmd = "objcopy"
}
attachCmdArgs = []string{"--add-section", ELFSectionName + "=" + tmpFile.Name(), objFile}
} In particular, the culprit seems to be I may be opinionated here, but i think that you should default to |
I'll look at this more closely later today and tomorrow. I am fine with the objcopy thing, but the main thing is it will need to be documented in the README.md, especially the environment variable. But thanks for all your effort! |
So it wouldn't hurt to go the extra yards to support the --target=ARCHSTRING would it? That would have to be done
|
Thanks Ian! It is actually my first time writing real Go code, so i didn't quite know what Go's idiomatic way was, I just went with trial & error and found Tomorrow morning I'll get back at the pull request & add this change & remove the Perhaps we should also add a couple lines in the README.md mentioning that cross compilation is supported, but needs the GLLVM_OBJCOPY env var as well? On a side note (again, first time Golang user), i noticed that when i forked the project, the change in URL messed up all the |
Yes the url thing is a pain in the ass. I know of no way around it, but my go-fu is on the wain. Yes mentioning cross-compiling requires GLLVM_OBJCOPY would be good and may save someone else some pain! |
Hello, I am already using
gclang
/gclang++
successfully on a project for which LLVM bytecode is extracted, processed and finally lowered to (native) machine code.I need to perform the exact same task, but in a cross-compilation setting. I expected this to be rather easy since by Clang's design, it is sufficient to pass a
--target=my_architecture
as a flag when building. As it turns out,gclang
does not recognize this flag, and ends up with a bad call toobjcopy
.Minimal reproducible example
You just need the simplest possible C program to reproduce this. I wrote the program in the file
a.c
:Then we run
clang
ona.c
and verify that an aarch64 executable is successfully created:Doing the exact same with
gclang
results in an error:I paste the error below:
If i run
gclang
with the-v
flag, i get:Is there an easy user-side fix to this problem? Or does it need a source code modification? This problem is mentioned in #63 , and it is hinted to have a look at parser.go, but the author didn't follow up, and i didn't find relevant pull requests.
The text was updated successfully, but these errors were encountered: