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

Support cross-compilation via -target ... option #72

Merged
merged 3 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,23 @@ This can be done by setting the `LTO_LINKING_FLAGS` to be something like
`"-g -Wl,-plugin-opt=save-temps"` which will be appended to the flags at link time.
This will at least preserve the bitcode files, even if `get-bc` will not be able to retrieve them for you.

## Cross-compilation notes

When cross-compiling a project (i.e. you pass the `--target=` or `-target` flag to the compiler),
you'll need to set the `GLLVM_OBJCOPY` variable to either
* `llvm-objcopy` to use LLVM's objcopy, which naturally supports all targets that clang does.
* `YOUR-TARGET-TRIPLE-objcopy` to use GNU's objcopy, since `objcopy` only supports the native architecture.

Example:
```sh
# test program
echo 'int main() { return 0; }' > a.c
clang --target=aarch64-linux-gnu a.c # works
gclang --target=aarch64-linux-gnu a.c # breaks
GLLVM_OBJCOPY=llvm-objcopy gclang --target=aarch64-linux-gnu a.c # works
GLLVM_OBJCOPY=aarch64-linux-gnu-objcopy gclang --target=aarch64-linux-gnu a.c # works if you have GNU's arm64 toolchain
```

## Developer tools

Debugging usually boils down to looking in the logs, maybe adding a print statement or two.
Expand Down
4 changes: 4 additions & 0 deletions shared/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,8 @@ func Parse(argList []string) ParserResult {
"--param": {1, pr.defaultBinaryCallback},
"-aux-info": {1, pr.defaultBinaryCallback},

"-target": {1, pr.compileLinkBinaryCallback},

"--version": {0, pr.compileOnlyCallback},
"-v": {0, pr.compileOnlyCallback},

Expand Down Expand Up @@ -400,6 +402,8 @@ func Parse(argList []string) ParserResult {
{`^.+\.(o|lo|So|so|po|a|dylib|pico|nossppico)$`, flagInfo{0, pr.objectFileCallback}}, //iam: pico and nossppico are FreeBSD
{`^.+\.dylib(\.\d)+$`, flagInfo{0, pr.objectFileCallback}},
{`^.+\.(So|so)(\.\d)+$`, flagInfo{0, pr.objectFileCallback}},

{`^--target=.+$`, flagInfo{0, pr.compileLinkUnaryCallback}},
}

for len(argList) > 0 {
Expand Down
Loading