From cb1a5e6713a4686d20b0c0bc5b1b184ba636749d Mon Sep 17 00:00:00 2001 From: Umberto Valleriani Date: Wed, 23 Aug 2023 09:46:16 +0200 Subject: [PATCH 1/3] add -target flag --- shared/parser.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shared/parser.go b/shared/parser.go index ac098fa..0fdf682 100644 --- a/shared/parser.go +++ b/shared/parser.go @@ -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}, From fa0b9ea188eb4038eb3ad378b56f7cc695b69066 Mon Sep 17 00:00:00 2001 From: Umberto Valleriani Date: Thu, 24 Aug 2023 08:49:03 +0200 Subject: [PATCH 2/3] add `--target=ARCH` in addition to `-target ARCH` --- shared/parser.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/shared/parser.go b/shared/parser.go index 0fdf682..5b691fa 100644 --- a/shared/parser.go +++ b/shared/parser.go @@ -402,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 { From 2ca524bbc1f0b03ec5c661cc38cbf7a219bc3047 Mon Sep 17 00:00:00 2001 From: Umberto Valleriani Date: Thu, 24 Aug 2023 09:03:26 +0200 Subject: [PATCH 3/3] edit readme to document cross-compilation --- README.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/README.md b/README.md index 909000c..bd77421 100644 --- a/README.md +++ b/README.md @@ -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.