mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
musl-based linux distro support (#2577)
* added switch statement to link musl-based linux distros to ld-musl-x86-64.so.2
* Update linker.c
/lib/ld-musl-x86-64.so.1 is musl's ld so. My bad
* don't need ENV_MUSLEABI.* in the switch for x86_64
* typo
* Added a CI test for an Alpine Linux container
* Update main.yml
Forgot to have bundle_output job use `env.LLVM_RELEASE_VERSION_ALPINEv3_22`.
* Added env.LLVM_RELEASE_VERSION_ALPINEv3_22 to `upload artifacts`
* changed bundle name to c3-musl-${{matrix,build_type}}.tar.gz
* Undid an accidental name change in build-linux-ubuntu22
* Update main.yml
sudo doesn't exist in alpine by default, and runs in root by default.
* Update main.yml
* Update main.yml
* Update main.yml
* Update main.yml
`--linker=builtin` fails because it forces search of `/lib64/ld-linux-x86-64.so.2`. lib64 doesn't exist on musl unless created as a symlink, and the appropriate so is /lib/ld-musl-<arch>.so.1
* Update main.yml
* Update main.yml
* Update main.yml
* Update main.yml
make isn't in alpine by default. added it in for risc-v example.
* gcc-riscv-none-elf is alpine's package
* using realpath for c3c over using relative pathing
* Have to use relative path for arguments in compiler test
* added --linker=builtin to
* Added linux-musl-<arch> targets
* Added more ld targets for glibc
* set both testproject libs as folders until they behave better
* added linux-musl-x64 target to clib2
* added riscv targets for ld-linux
* ubuntu doesn't have ld in /lib, but solely in /lib64?
* Make MUSL distinct from the target.
* Fix default in project schema
* Fix define
* Fix manifests.
* Update main.yml
add --linux-libc flag for builtin linking
* Grammar refresh
* Update releasenotes.
---------
Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
This commit is contained in:
committed by
GitHub
parent
ce0ab62c78
commit
ccffa03de2
182
.github/workflows/main.yml
vendored
182
.github/workflows/main.yml
vendored
@@ -12,6 +12,7 @@ env:
|
||||
LLVM_RELEASE_VERSION_LINUX: 19
|
||||
LLVM_RELEASE_VERSION_OPENBSD: 19
|
||||
LLVM_RELEASE_VERSION_UBUNTU22: 19
|
||||
LLVM_RELEASE_VERSION_ALPINEv3_22: 20
|
||||
LLVM_DEV_VERSION: 22
|
||||
jobs:
|
||||
|
||||
@@ -409,6 +410,187 @@ jobs:
|
||||
name: c3-linux-${{matrix.build_type}}
|
||||
path: c3-linux-${{matrix.build_type}}.tar.gz
|
||||
|
||||
build-linux-alpine:
|
||||
runs-on: ubuntu-22.04
|
||||
container:
|
||||
image: alpine:3.22
|
||||
strategy:
|
||||
# Don't abort runners if a single one fails
|
||||
fail-fast: false
|
||||
matrix:
|
||||
build_type: [Release, Debug]
|
||||
llvm_version: [18, 19, 20]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Install common deps
|
||||
run: |
|
||||
apk update
|
||||
apk add zlib-dev zlib-static python3 samurai cmake curl-dev curl-static openssl-dev
|
||||
|
||||
- name: Install Clang ${{matrix.llvm_version}}
|
||||
run: |
|
||||
apk add "llvm${{matrix.llvm_version}}-dev" "llvm${{matrix.llvm_version}}-static" \
|
||||
"llvm${{matrix.llvm_version}}-gtest" "llvm${{matrix.llvm_version}}-linker-tools" \
|
||||
"llvm${{matrix.llvm_version}}-test-utils" "llvm${{matrix.llvm_version}}-test-utils-pyc" \
|
||||
"lld${{matrix.llvm_version}}-dev" "clang${{matrix.llvm_version}}-dev" \
|
||||
"clang${{matrix.llvm_version}}-extra-tools" "clang${{matrix.llvm_version}}-static"
|
||||
- name: CMake
|
||||
if: matrix.llvm_version == env.LLVM_DEV_VERSION
|
||||
run: |
|
||||
cmake -B build \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=${{matrix.build_type}}" \
|
||||
-DCMAKE_C_COMPILER=clang-${{matrix.llvm_version}} \
|
||||
-DCMAKE_CXX_COMPILER=clang++-${{matrix.llvm_version}} \
|
||||
-DCMAKE_LINKER=lld-link-${{matrix.llvm_version}} \
|
||||
-DCMAKE_OBJCOPY=llvm-objcopy-${{matrix.llvm_version}} \
|
||||
-DCMAKE_STRIP=llvm-strip-${{matrix.llvm_version}} \
|
||||
-DCMAKE_DLLTOOL=llvm-dlltool-${{matrix.llvm_version}} \
|
||||
-DLLVM_ENABLE_LIBXML2=OFF \
|
||||
-DC3_LINK_DYNAMIC=ON \
|
||||
-DC3_LLVM_VERSION=${{matrix.llvm_version}}
|
||||
cmake --build build
|
||||
- name: CMake_Stable
|
||||
if: matrix.llvm_version >= 18 && matrix.llvm_version != env.LLVM_DEV_VERSION
|
||||
run: |
|
||||
cmake -B build \
|
||||
-G Ninja \
|
||||
-DCMAKE_BUILD_TYPE=${{matrix.build_type}} \
|
||||
-DCMAKE_C_COMPILER=clang-${{matrix.llvm_version}} \
|
||||
-DCMAKE_CXX_COMPILER=clang++-${{matrix.llvm_version}} \
|
||||
-DCMAKE_LINKER=lld-link-${{matrix.llvm_version}} \
|
||||
-DCMAKE_OBJCOPY=llvm-objcopy-${{matrix.llvm_version}} \
|
||||
-DCMAKE_STRIP=llvm-strip-${{matrix.llvm_version}} \
|
||||
-DCMAKE_DLLTOOL=llvm-dlltool-${{matrix.llvm_version}} \
|
||||
-DLLVM_ENABLE_LIBXML2=OFF \
|
||||
-DC3_LINK_DYNAMIC=ON \
|
||||
-DC3_LLVM_VERSION=${{matrix.llvm_version}}.1
|
||||
cmake --build build
|
||||
|
||||
- name: Compile and run some examples
|
||||
run: |
|
||||
export C3C="$(realpath ./build/c3c)"
|
||||
cd resources
|
||||
"$C3C" compile examples/base64.c3
|
||||
"$C3C" compile examples/binarydigits.c3
|
||||
"$C3C" compile examples/brainfk.c3
|
||||
"$C3C" compile examples/factorial_macro.c3
|
||||
"$C3C" compile examples/fasta.c3
|
||||
"$C3C" compile examples/gameoflife.c3
|
||||
"$C3C" compile examples/hash.c3
|
||||
"$C3C" compile-only examples/levenshtein.c3
|
||||
"$C3C" compile examples/load_world.c3
|
||||
"$C3C" compile-only examples/map.c3
|
||||
"$C3C" compile examples/mandelbrot.c3
|
||||
"$C3C" compile examples/plus_minus.c3
|
||||
"$C3C" compile examples/nbodies.c3
|
||||
"$C3C" compile examples/spectralnorm.c3
|
||||
"$C3C" compile examples/swap.c3
|
||||
"$C3C" compile examples/contextfree/boolerr.c3
|
||||
"$C3C" compile examples/contextfree/dynscope.c3
|
||||
"$C3C" compile examples/contextfree/guess_number.c3
|
||||
"$C3C" compile examples/contextfree/multi.c3
|
||||
"$C3C" compile examples/contextfree/cleanup.c3
|
||||
"$C3C" compile-run examples/hello_world_many.c3
|
||||
"$C3C" compile-run examples/time.c3
|
||||
"$C3C" compile-run examples/fannkuch-redux.c3
|
||||
"$C3C" compile-run examples/contextfree/boolerr.c3
|
||||
"$C3C" compile-run examples/load_world.c3
|
||||
"$C3C" compile-run examples/process.c3
|
||||
"$C3C" compile-run examples/ls.c3
|
||||
# "$C3C" compile-run --linker=builtin linux_stack.c3 # Program will hang due to incorrect linking to `/lib64/ld-linux-x86-64.so.2` instead of `/lib/ld-musl-x86_64.so.1`
|
||||
"$C3C" compile-run linux_stack.c3
|
||||
"$C3C" compile-run examples/args.c3 -- foo -bar "baz baz"
|
||||
|
||||
- name: Compile and run dynlib-test
|
||||
run: |
|
||||
export C3C="$(realpath ./build/c3c)"
|
||||
cd resources/examples/dynlib-test
|
||||
"$C3C" -vv dynamic-lib add.c3
|
||||
mv add.so libadd.so
|
||||
cc test.c -L. -ladd -Wl,-rpath=.
|
||||
./a.out
|
||||
"$C3C" compile-run test.c3 -L . -l add -z -Wl,-rpath=.
|
||||
|
||||
- name: Compile and run staticlib-test
|
||||
run: |
|
||||
export C3C="$(realpath ./build/c3c)"
|
||||
cd resources/examples/staticlib-test
|
||||
"$C3C" -vv static-lib add.c3
|
||||
mv add.a libadd.a
|
||||
cc test.c -L. -ladd
|
||||
./a.out
|
||||
"$C3C" compile-run test.c3 -L . -l add
|
||||
|
||||
- name: Compile run unit tests
|
||||
run: |
|
||||
export C3C="$(realpath ./build/c3c)"
|
||||
cd test
|
||||
"$C3C" compile-test unit -D SLOW_TESTS
|
||||
|
||||
- name: Build testproject
|
||||
run: |
|
||||
export C3C="$(realpath ./build/c3c)"
|
||||
cd resources/testproject
|
||||
"$C3C" run -vvv --trust=full
|
||||
|
||||
- name: Test WASM
|
||||
run: |
|
||||
export C3C="$(realpath ./build/c3c)"
|
||||
cd resources/testfragments
|
||||
"$C3C" compile --target wasm32 -g0 --no-entry -Os wasm4.c3
|
||||
|
||||
- name: Install QEMU and Risc-V toolchain
|
||||
run: |
|
||||
apk add qemu-dev qemu-system-riscv32 gcc-riscv-none-elf make
|
||||
|
||||
- name: Compile and run Baremetal Risc-V Example
|
||||
run: |
|
||||
cd resources/examples/embedded/riscv-qemu
|
||||
make C3C_PATH=../../../../build/ run
|
||||
|
||||
- name: Build testproject direct linker
|
||||
run: |
|
||||
export C3C="$(realpath ./build/c3c)"
|
||||
cd resources/testproject
|
||||
"$C3C" run -vvv --linker=builtin --trust=full --linux-libc=musl
|
||||
|
||||
- name: Init a library & a project
|
||||
run: |
|
||||
./build/c3c init-lib mylib
|
||||
ls mylib.c3l
|
||||
./build/c3c init myproject
|
||||
ls myproject
|
||||
|
||||
- name: Vendor-fetch
|
||||
run: |
|
||||
"$(realpath ./build/c3c)" vendor-fetch raylib55
|
||||
|
||||
- name: run compiler tests
|
||||
run: |
|
||||
export C3C="$(realpath ./build/c3c)"
|
||||
cd test
|
||||
"$C3C" compile-run -O1 src/test_suite_runner.c3 -- ../build/c3c test_suite/
|
||||
|
||||
- name: bundle_output
|
||||
if: matrix.llvm_version == env.LLVM_RELEASE_VERSION_ALPINEv3_22
|
||||
run: |
|
||||
mkdir c3
|
||||
cp -r lib c3
|
||||
cp msvc_build_libraries.py c3
|
||||
cp build/c3c c3
|
||||
cp README.md c3
|
||||
cp releasenotes.md c3
|
||||
tar -czf c3-musl-${{matrix.build_type}}.tar.gz c3
|
||||
|
||||
- name: upload artifacts
|
||||
if: matrix.llvm_version == env.LLVM_RELEASE_VERSION_ALPINEv3_22
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: c3-musl-${{matrix.build_type}}
|
||||
path: c3-musl-${{matrix.build_type}}.tar.gz
|
||||
|
||||
build-linux-ubuntu22:
|
||||
runs-on: ubuntu-22.04
|
||||
strategy:
|
||||
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@@ -92,3 +92,8 @@ result
|
||||
/test/tmp/*
|
||||
/test/testrun
|
||||
/test/test_suite_runner
|
||||
|
||||
# patches, originals and rejects
|
||||
*.patch
|
||||
*.rej
|
||||
*.orig
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
- Xtensa target no longer enabled by default on LLVM 22, Compile with `-DXTENSA_ENABLE` to enable it instead
|
||||
- Add `float[<3>] x = { .xy = 1.2, .z = 3.3 }` swizzle initialization for vectors. #2599
|
||||
- Support `int $foo...` arguments. #2601
|
||||
- Add musl support with `--linux-libc=musl`.
|
||||
|
||||
### Fixes
|
||||
- `Foo.is_eq` would return false if the type was a `typedef` and had an overload, but the underlying type was not comparable.
|
||||
|
||||
@@ -6,10 +6,12 @@ hello.a: $(SRCS_C3)
|
||||
$(C3C_PATH)c3c -g --use-stdlib=no --no-entry --target elf-riscv32 static-lib $(SRCS_C3)
|
||||
|
||||
start.o: start.s
|
||||
riscv64-unknown-elf-as -g -march=rv32i -mabi=ilp32 -misa-spec=20191213 -o start.o start.s
|
||||
riscv64-unknown-elf-as -g -march=rv32i -mabi=ilp32 -misa-spec=20191213 -o start.o start.s \
|
||||
|| riscv-none-elf-as -g -march=rv32i -mabi=ilp32 -misa-spec=20191213 -o start.o start.s
|
||||
|
||||
hello.elf: hello.a start.o baremetal.ld
|
||||
riscv64-unknown-elf-ld -T baremetal.ld -m elf32lriscv -o hello.elf hello.a start.o
|
||||
riscv64-unknown-elf-ld -T baremetal.ld -m elf32lriscv -o hello.elf hello.a start.o \
|
||||
|| riscv-none-elf-ld -T baremetal.ld -m elf32lriscv -o hello.elf hello.a start.o
|
||||
|
||||
run: hello.elf
|
||||
qemu-system-riscv32 -nographic -serial mon:stdio -machine virt -semihosting -bios hello.elf
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -199,6 +199,15 @@
|
||||
"description": "Include the standard library.",
|
||||
"default": true
|
||||
},
|
||||
"linux-libc": {
|
||||
"type": "string",
|
||||
"description": "Set the libc to use for Linux.",
|
||||
"enum": [
|
||||
"gnu",
|
||||
"musl"
|
||||
],
|
||||
"default": "gnu"
|
||||
},
|
||||
"x86cpu": {
|
||||
"type": "string",
|
||||
"description": "Set general level of x64 cpu.",
|
||||
|
||||
@@ -1,15 +1,19 @@
|
||||
{
|
||||
"provides" : "clib",
|
||||
"c-sources" : ["hello2.c", "whitespace test.c"],
|
||||
"targets" : {
|
||||
"macos-x64" : {
|
||||
},
|
||||
"macos-aarch64" : {},
|
||||
"linux-x64" : {
|
||||
{
|
||||
"provides": "clib",
|
||||
"c-sources": [
|
||||
"hello2.c",
|
||||
"whitespace test.c"
|
||||
],
|
||||
"targets": {
|
||||
"macos-x64": {},
|
||||
"macos-aarch64": {},
|
||||
"linux-x64": {
|
||||
"cflags": "-fPIE"
|
||||
},
|
||||
"windows-x64" : {
|
||||
"c-include-dirs": ["C:\\"]
|
||||
"windows-x64": {
|
||||
"c-include-dirs": [
|
||||
"C:\\"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
BIN
resources/testproject/lib/clib2.c3l/__MACOSX/._manifest.json
Normal file
BIN
resources/testproject/lib/clib2.c3l/__MACOSX/._manifest.json
Normal file
Binary file not shown.
3
resources/testproject/lib/clib2.c3l/clib2.c3i
Normal file
3
resources/testproject/lib/clib2.c3l/clib2.c3i
Normal file
@@ -0,0 +1,3 @@
|
||||
module clib2;
|
||||
|
||||
extern fn void hello_from_c_zip();
|
||||
5
resources/testproject/lib/clib2.c3l/hello.c
Normal file
5
resources/testproject/lib/clib2.c3l/hello.c
Normal file
@@ -0,0 +1,5 @@
|
||||
#include <stdio.h>
|
||||
void hello_from_c_zip(void)
|
||||
{
|
||||
puts("Hello from C Zip!");
|
||||
}
|
||||
14
resources/testproject/lib/clib2.c3l/manifest.json
Normal file
14
resources/testproject/lib/clib2.c3l/manifest.json
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"provides": "clib2",
|
||||
"c-sources": [
|
||||
"hello.c"
|
||||
],
|
||||
"targets": {
|
||||
"macos-x64": {},
|
||||
"macos-aarch64": {},
|
||||
"linux-x64": {
|
||||
"cflags-override": "-fPIE"
|
||||
},
|
||||
"windows-x64": {}
|
||||
}
|
||||
}
|
||||
@@ -103,6 +103,13 @@ typedef enum
|
||||
LINKER_TYPE_CUSTOM = 2,
|
||||
} LinkerType;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
LINUX_LIBC_NOT_SET = -1,
|
||||
LINUX_LIBC_GNU = 0,
|
||||
LINUX_LIBC_MUSL = 1,
|
||||
} LinuxLibc;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TRUST_NONE,
|
||||
@@ -607,6 +614,7 @@ typedef struct BuildOptions_
|
||||
OptimizationLevel optlevel;
|
||||
SizeOptimizationLevel optsize;
|
||||
RiscvAbi riscv_abi;
|
||||
LinuxLibc linux_libc;
|
||||
MemoryEnvironment memory_environment;
|
||||
SanitizeMode sanitize_mode;
|
||||
uint32_t max_vector_size;
|
||||
@@ -808,6 +816,7 @@ typedef struct
|
||||
} win;
|
||||
struct
|
||||
{
|
||||
LinuxLibc libc;
|
||||
const char *crt;
|
||||
const char *crtbegin;
|
||||
} linuxpaths;
|
||||
@@ -878,6 +887,7 @@ static BuildTarget default_build_target = {
|
||||
.feature.panic_level = PANIC_NOT_SET,
|
||||
.win.crt_linking = WIN_CRT_DEFAULT,
|
||||
.win.def = NULL,
|
||||
.linuxpaths.libc = LINUX_LIBC_GNU,
|
||||
.switchrange_max_size = DEFAULT_SWITCHRANGE_MAX_SIZE,
|
||||
.switchjump_max_size = DEFAULT_SWITCH_JUMP_MAX_SIZE,
|
||||
.quiet = false,
|
||||
|
||||
@@ -50,6 +50,11 @@ static const char *optsizes[3] = {
|
||||
[SIZE_OPTIMIZATION_TINY] = "tiny",
|
||||
};
|
||||
|
||||
static const char *linuxlibc[2] = {
|
||||
[LINUX_LIBC_GNU] = "gnu",
|
||||
[LINUX_LIBC_MUSL] = "musl",
|
||||
};
|
||||
|
||||
static const char *linker_kind[3] = {
|
||||
[LINKER_TYPE_BUILTIN] = "builtin",
|
||||
[LINKER_TYPE_CC] = "cc",
|
||||
|
||||
@@ -216,6 +216,7 @@ static void usage(bool full)
|
||||
print_opt("--macos-min-version <ver>", "Set the minimum MacOS version to compile for.");
|
||||
print_opt("--macos-sdk-version <ver>", "Set the MacOS SDK compiled for.");
|
||||
PRINTF("");
|
||||
print_opt("--linux-libc=<gnu|musl>", "Set the libc to use on Linux, defaults to gnu.");
|
||||
print_opt("--linux-crt <dir>", "Set the directory to use for finding crt1.o and related files.");
|
||||
print_opt("--linux-crtbegin <dir>", "Set the directory to use for finding crtbegin.o and related files.");
|
||||
PRINTF("");
|
||||
@@ -861,6 +862,11 @@ static void parse_option(BuildOptions *options)
|
||||
options->fp_math = parse_opt_select(FpOpt, argopt, fp_math);
|
||||
return;
|
||||
}
|
||||
if ((argopt = match_argopt("linux-libc")))
|
||||
{
|
||||
options->linux_libc = parse_opt_select(LinuxLibc, argopt, linuxlibc);
|
||||
return;
|
||||
}
|
||||
if ((argopt = match_argopt("optsize")))
|
||||
{
|
||||
options->optsize = parse_opt_select(SizeOptimizationLevel, argopt, optsizes);
|
||||
@@ -1495,6 +1501,7 @@ BuildOptions parse_arguments(int argc, const char *argv[])
|
||||
.merge_functions = MERGE_FUNCTIONS_NOT_SET,
|
||||
.slp_vectorization = VECTORIZATION_NOT_SET,
|
||||
.loop_vectorization = VECTORIZATION_NOT_SET,
|
||||
.linux_libc = LINUX_LIBC_NOT_SET,
|
||||
.files = NULL,
|
||||
.build_dir = NULL,
|
||||
.output_dir = NULL,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
// Copyright (c) 2019-2023 Christoffer Lerno. All rights reserved.
|
||||
// Use of this source code is governed by a LGPLv3.0
|
||||
// a copy of which can be found in the LICENSE file.
|
||||
#include "build.h"
|
||||
#include "build_internal.h"
|
||||
|
||||
void load_library_files(void) {}
|
||||
@@ -14,6 +15,13 @@ ArchOsTarget default_target = MACOS_X64;
|
||||
ArchOsTarget default_target = ANDROID_X86_64;
|
||||
#elif defined(__linux__) && __linux__
|
||||
ArchOsTarget default_target = LINUX_X64;
|
||||
#if (defined(__GLIBC__) && __GLIBC__) || (defined(__GLIBC_MINOR__) && __GLIBC_MINOR__)
|
||||
#define LINUX_LIBC
|
||||
LinuxLibc default_libc = LINUX_LIBC_GNU;
|
||||
#elif defined(__DEFINED_va_list)
|
||||
#define LINUX_LIBC
|
||||
LinuxLibc default_libc = LINUX_LIBC_MUSL;
|
||||
#endif
|
||||
#elif defined(__NetBSD__)
|
||||
ArchOsTarget default_target = NETBSD_X64;
|
||||
#elif defined(__FreeBSD__)
|
||||
@@ -30,12 +38,26 @@ ArchOsTarget default_target = MACOS_AARCH64;
|
||||
ArchOsTarget default_target = ANDROID_AARCH64;
|
||||
#elif defined(__linux__) && __linux__
|
||||
ArchOsTarget default_target = LINUX_AARCH64;
|
||||
#if (defined(__GLIBC__) && __GLIBC__) || (defined(__GLIBC_MINOR__) && __GLIBC_MINOR__)
|
||||
#define LINUX_LIBC
|
||||
LinuxLibc default_libc = LINUX_LIBC_GNU;
|
||||
#elif defined(__DEFINED_va_list)
|
||||
#define LINUX_LIBC
|
||||
LinuxLibc default_libc = LINUX_LIBC_MUSL;
|
||||
#endif
|
||||
#else
|
||||
ArchOsTarget default_target = ELF_AARCH64;
|
||||
#endif
|
||||
#elif defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86)
|
||||
#if defined(__linux__) && __linux__
|
||||
ArchOsTarget default_target = LINUX_X86;
|
||||
#if (defined(__GLIBC__) && __GLIBC__) || (defined(__GLIBC_MINOR__) && __GLIBC_MINOR__)
|
||||
#define LINUX_LIBC
|
||||
LinuxLibc default_libc = LINUX_LIBC_GNU;
|
||||
#elif defined(__DEFINED_va_list)
|
||||
#define LINUX_LIBC
|
||||
LinuxLibc default_libc = LINUX_LIBC_MUSL;
|
||||
#endif
|
||||
#elif defined(__FreeBSD__)
|
||||
ArchOsTarget default_target = FREEBSD_X86;
|
||||
#elif defined(__OpenBSD__)
|
||||
@@ -50,12 +72,26 @@ ArchOsTarget default_target = ELF_X86;
|
||||
#elif defined(__riscv32)
|
||||
#if defined(__linux__) && __linux__
|
||||
ArchOsTarget default_target = LINUX_RISCV32;
|
||||
#if (defined(__GLIBC__) && __GLIBC__) || (defined(__GLIBC_MINOR__) && __GLIBC_MINOR__)
|
||||
#define LINUX_LIBC
|
||||
LinuxLibc default_libc = LINUX_LIBC_GNU;
|
||||
#elif defined(__DEFINED_va_list)
|
||||
#define LINUX_LIBC
|
||||
LinuxLibc default_libc = LINUX_LIBC_MUSL;
|
||||
#endif
|
||||
#else
|
||||
ArchOsTarget default_target = ELF_RISCV32;
|
||||
#endif
|
||||
#elif defined(__riscv64)
|
||||
#if defined(__linux__) && __linux__
|
||||
ArchOsTarget default_target = LINUX_RISCV64;
|
||||
#if (defined(__GLIBC__) && __GLIBC__) || (defined(__GLIBC_MINOR__) && __GLIBC_MINOR__)
|
||||
#define LINUX_LIBC
|
||||
LinuxLibc default_libc = LINUX_LIBC_GNU;
|
||||
#elif defined(__DEFINED_va_list)
|
||||
#define LINUX_LIBC
|
||||
LinuxLibc default_libc = LINUX_LIBC_MUSL;
|
||||
#endif
|
||||
#else
|
||||
ArchOsTarget default_target = ELF_RISCV64;
|
||||
#endif
|
||||
@@ -63,6 +99,10 @@ ArchOsTarget default_target = ELF_RISCV64;
|
||||
ArchOsTarget default_target = ARCH_OS_TARGET_DEFAULT;
|
||||
#endif
|
||||
|
||||
#ifndef LINUX_LIBC
|
||||
LinuxLibc default_libc = LINUX_LIBC_GNU;
|
||||
#endif
|
||||
|
||||
bool command_accepts_files(CompilerCommand command)
|
||||
{
|
||||
switch (command)
|
||||
@@ -428,7 +468,7 @@ static void update_build_target_from_options(BuildTarget *target, BuildOptions *
|
||||
set_if_updated(target->feature.riscv_cpu_set, options->riscv_cpu_set);
|
||||
set_if_updated(target->feature.riscv_abi, options->riscv_abi);
|
||||
set_if_updated(target->feature.win_debug, options->win_debug);
|
||||
|
||||
set_if_updated(target->linuxpaths.libc, options->linux_libc);
|
||||
set_if_updated(target->feature.pass_win64_simd_as_arrays, options->win_64_simd);
|
||||
|
||||
OVERRIDE_IF_SET(output_dir);
|
||||
|
||||
@@ -31,6 +31,7 @@ const char *project_default_keys[][2] = {
|
||||
{"linker-search-paths", "Linker search paths."},
|
||||
{"linux-crt", "Set the directory to use for finding crt1.o and related files."},
|
||||
{"linux-crtbegin", "Set the directory to use for finding crtbegin.o and related files."},
|
||||
{"linux-libc", "Set the libc to use for Linux. Valid options are 'gnu' and 'musl', default is 'gnu'"},
|
||||
{"loop-vectorize", "Force enable/disable loop auto-vectorization."},
|
||||
{"macos-min-version", "Set the minimum MacOS version to compile for."},
|
||||
{"macos-sdk-version", "Set the MacOS SDK compiled for." },
|
||||
@@ -115,6 +116,7 @@ const char* project_target_keys[][2] = {
|
||||
{"linker-search-paths-override", "Linker search paths for this target, overriding global settings."},
|
||||
{"linux-crt", "Set the directory to use for finding crt1.o and related files."},
|
||||
{"linux-crtbegin", "Set the directory to use for finding crtbegin.o and related files."},
|
||||
{"linux-libc", "Set the libc to use for Linux. Valid options are 'gnu' and 'musl', default is 'gnu'"},
|
||||
{"loop-vectorize", "Force enable/disable loop auto-vectorization."},
|
||||
{"macos-min-version", "Set the minimum MacOS version to compile for."},
|
||||
{"macos-sdk-version", "Set the MacOS SDK compiled for." },
|
||||
@@ -483,6 +485,10 @@ static void load_into_build_target(BuildParseContext context, JSONObject *json,
|
||||
// Linux crtbegin
|
||||
target->linuxpaths.crtbegin = get_string(context, json, "linux-crtbegin", target->linuxpaths.crtbegin);
|
||||
|
||||
// linux-libc
|
||||
LinuxLibc linux_libc = GET_SETTING(LinuxLibc, "linux-libc", linuxlibc, "`gnu` or `musl`.");
|
||||
if (linux_libc > -1) target->linuxpaths.libc = linux_libc;
|
||||
|
||||
// version
|
||||
target->version = get_string(context, json, "version", target->version);
|
||||
|
||||
|
||||
@@ -331,6 +331,7 @@ static const char *find_arch_glob_path(const char *glob_path, int file_len)
|
||||
|
||||
static const char *get_linux_crt_arch_glob(void)
|
||||
{
|
||||
if (compiler.build.linuxpaths.libc == LINUX_LIBC_MUSL) return "/usr/lib/*/crt1.o";
|
||||
switch (compiler.build.arch_os_target)
|
||||
{
|
||||
case LINUX_X64:
|
||||
@@ -348,6 +349,7 @@ static const char *get_linux_crt_arch_glob(void)
|
||||
|
||||
static const char *get_linux_crt_begin_arch_glob(void)
|
||||
{
|
||||
if (compiler.build.linuxpaths.libc == LINUX_LIBC_MUSL) return "/usr/lib/gcc/*/*/crtbegin.o";
|
||||
switch (compiler.build.arch_os_target)
|
||||
{
|
||||
case LINUX_X64:
|
||||
@@ -398,6 +400,56 @@ static const char *find_linux_crt_begin(void)
|
||||
return path;
|
||||
}
|
||||
|
||||
static const char *find_linux_ld(void)
|
||||
{
|
||||
INFO_LOG("Environment Type ID: %d", compiler.platform.environment_type);
|
||||
switch (compiler.platform.environment_type)
|
||||
{
|
||||
case ENV_TYPE_MUSL:
|
||||
case ENV_TYPE_MUSLEABI:
|
||||
case ENV_TYPE_MUSLEABIHF:
|
||||
switch (compiler.platform.arch)
|
||||
{
|
||||
case ARCH_TYPE_ARM: return "--dynamic-linker=/lib/ld-musl-arm.so.1";
|
||||
case ARCH_TYPE_ARMB: return "--dynamic-linker=/lib/ld-musl-armeb.so.1";
|
||||
case ARCH_TYPE_AARCH64: return "--dynamic-linker=/lib/ld-musl-aarch64.so.1";
|
||||
case ARCH_TYPE_AARCH64_BE: return "--dynamic-linker=/lib/ld-musl-aarch64_be.so.1";
|
||||
case ARCH_TYPE_MIPS: return "--dynamic-linker=/lib/ld-musl-mips.so.1";
|
||||
case ARCH_TYPE_MIPSEL: return "--dynamic-linker=/lib/ld-musl-mipsel.so.1";
|
||||
case ARCH_TYPE_MIPS64: return "--dynamic-linker=/lib/ld-musl-mips64.so.1";
|
||||
case ARCH_TYPE_MIPS64EL: return "--dynamic-linker=/lib/ld-musl-mips64el.so.1";
|
||||
case ARCH_TYPE_PPC: return "--dynamic-linker=/lib/ld-musl-powerpc.so.1";
|
||||
case ARCH_TYPE_PPC64: return "--dynamic-linker=/lib/ld-musl-powerpc64.so.1";
|
||||
case ARCH_TYPE_RISCV32: return "--dynamic-linker=/lib/ld-musl-riscv32.so.1";
|
||||
case ARCH_TYPE_RISCV64: return "--dynamic-linker=/lib/ld-musl-riscv64.so.1";
|
||||
case ARCH_TYPE_X86: return "--dynamic-linker=/lib/ld-musl-i386.so.1";
|
||||
case ARCH_TYPE_X86_64: return "--dynamic-linker=/lib/ld-musl-x86_64.so.1";
|
||||
default: return "--dynamic-linker=/lib/ld-musl-unknown.so.1"; // a placeholder for now
|
||||
}
|
||||
UNREACHABLE;
|
||||
break;
|
||||
case ENV_TYPE_ANDROID:
|
||||
return "--dynamic-linker=/system/ld-android.so";
|
||||
default:
|
||||
switch (compiler.platform.arch) {
|
||||
case ARCH_TYPE_ARM: return "--dynamic-linker=/lib/ld-linux.so.3";
|
||||
case ARCH_TYPE_AARCH64: return "--dynamic-linker=/lib/ld-linux-aarch64.so.1";
|
||||
case ARCH_TYPE_MIPS: return "--dynamic-linker=/lib/ld-linux-mipsn8.so.1";
|
||||
case ARCH_TYPE_MIPSEL: return "--dynamic-linker=/lib/ld-linux-mipsn8.so.1";
|
||||
case ARCH_TYPE_MIPS64: return "--dynamic-linker=/lib/ld-linux-mipsn8.so.1";
|
||||
case ARCH_TYPE_MIPS64EL: return "--dynamic-linker=/lib/ld-linux-mipsn8.so.1";
|
||||
case ARCH_TYPE_RISCV32: return "-dynamic-linker=/lib/ld-linux-riscv32-ilp32.so.1";
|
||||
case ARCH_TYPE_RISCV64: return "-dynamic-linker=/lib/ld-linux-riscv64-lp64.so.1";
|
||||
case ARCH_TYPE_SPARCV9: return "--dynamic-linker=/lib/ld-linux.so.2";
|
||||
case ARCH_TYPE_X86: return "--dynamic-linker=/lib64/ld-linux.so.2";
|
||||
case ARCH_TYPE_X86_64: return "--dynamic-linker=/lib64/ld-linux-x86-64.so.2";
|
||||
default: return "--dynamic-linkrt=/lib/ld-linux-unknown.so.2"; // another placeholder until we have all of them
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
UNREACHABLE;
|
||||
}
|
||||
|
||||
static void linker_setup_linux(const char ***args_ref, Linker linker_type, bool is_dylib)
|
||||
{
|
||||
if (link_libc()) linking_add_link(&compiler.linking, "dl");
|
||||
@@ -452,7 +504,7 @@ static void linker_setup_linux(const char ***args_ref, Linker linker_type, bool
|
||||
}
|
||||
add_concat_file_arg(crt_dir, "crtn.o");
|
||||
add_concat_quote_arg("-L", crt_dir);
|
||||
add_plain_arg("--dynamic-linker=/lib64/ld-linux-x86-64.so.2");
|
||||
add_plain_arg(find_linux_ld());
|
||||
if (compiler.linking.link_math) linking_add_link(&compiler.linking, "m");
|
||||
linking_add_link(&compiler.linking, "pthread");
|
||||
linking_add_link(&compiler.linking, "c");
|
||||
|
||||
@@ -1172,35 +1172,41 @@ const char *arch_to_linker_arch(ArchType arch)
|
||||
UNREACHABLE;
|
||||
}
|
||||
|
||||
static char *arch_to_target_triple[ARCH_OS_TARGET_LAST + 1] = {
|
||||
[FREEBSD_X86] = "i386-unknown-freebsd",
|
||||
[OPENBSD_X86] = "i386-unknown-openbsd",
|
||||
[NETBSD_X86] = "i386-unknown-netbsd",
|
||||
[MCU_X86] = "i386-pc-elfiamcu",
|
||||
[LINUX_X86] = "i386-unknown-linux",
|
||||
[ELF_X86] = "i386-unknown-elf",
|
||||
[MACOS_X64] = "x86_64-apple-macosx",
|
||||
[LINUX_X64] = "x86_64-pc-linux-gnu",
|
||||
[WINDOWS_X64] = "x86_64-pc-windows-msvc",
|
||||
[MINGW_X64] = "x86_64-w64-windows-gnu",
|
||||
[NETBSD_X64] = "x86_64-pc-netbsd",
|
||||
[FREEBSD_X64] = "x86_64-pc-freebsd",
|
||||
[OPENBSD_X64] = "x86_64-pc-openbsd",
|
||||
[ELF_X64] = "x86_64-unknown-elf",
|
||||
[ANDROID_AARCH64] = "aarch64-linux-android",
|
||||
[ANDROID_X86_64] = "x86_64-linux-android",
|
||||
[LINUX_AARCH64] = "aarch64-unknown-linux-gnu",
|
||||
[IOS_AARCH64] = "aarch64-apple-ios",
|
||||
[MACOS_AARCH64] = "aarch64-apple-macosx",
|
||||
[ELF_AARCH64] = "aarch64-unknown-elf",
|
||||
[WINDOWS_AARCH64] = "aarch64-pc-windows-msvc",
|
||||
[LINUX_RISCV32] = "riscv32-unknown-linux",
|
||||
[ELF_RISCV32] = "riscv32-unknown-elf",
|
||||
[LINUX_RISCV64] = "riscv64-unknown-linux",
|
||||
[ELF_RISCV64] = "riscv64-unknown-elf",
|
||||
[ELF_XTENSA] = "xtensa-unknown-elf",
|
||||
[WASM32] = "wasm32-unknown-unknown",
|
||||
[WASM64] = "wasm64-unknown-unknown",
|
||||
static char *arch_to_target_triple(ArchOsTarget target, LinuxLibc linux_libc)
|
||||
{
|
||||
switch (target)
|
||||
{
|
||||
case FREEBSD_X86: return "i386-unknown-freebsd";
|
||||
case OPENBSD_X86: return "i386-unknown-openbsd";
|
||||
case NETBSD_X86: return "i386-unknown-netbsd";
|
||||
case MCU_X86: return "i386-pc-elfiamcu";
|
||||
case LINUX_X86: return linux_libc == LINUX_LIBC_MUSL ? "i386-unknown-linux-musl" : "i386-unknown-linux";
|
||||
case ELF_X86: return "i386-unknown-elf";
|
||||
case MACOS_X64: return "x86_64-apple-macosx";
|
||||
case LINUX_X64: return linux_libc == LINUX_LIBC_MUSL ? "x86_64-pc-linux-musl" : "x86_64-pc-linux-gnu";
|
||||
case WINDOWS_X64: return "x86_64-pc-windows-msvc";
|
||||
case MINGW_X64: return "x86_64-w64-windows-gnu";
|
||||
case NETBSD_X64: return "x86_64-pc-netbsd";
|
||||
case FREEBSD_X64: return "x86_64-pc-freebsd";
|
||||
case OPENBSD_X64: return "x86_64-pc-openbsd";
|
||||
case ELF_X64: return "x86_64-unknown-elf";
|
||||
case ANDROID_AARCH64: return "aarch64-linux-android";
|
||||
case ANDROID_X86_64: return "x86_64-linux-android";
|
||||
case LINUX_AARCH64: return linux_libc == LINUX_LIBC_MUSL ? "aarch64-unknown-linux-musl" : "aarch64-unknown-linux-gnu";
|
||||
case IOS_AARCH64: return "aarch64-apple-ios";
|
||||
case MACOS_AARCH64: return "aarch64-apple-macosx";
|
||||
case ELF_AARCH64: return "aarch64-unknown-elf";
|
||||
case WINDOWS_AARCH64: return "aarch64-pc-windows-msvc";
|
||||
case LINUX_RISCV32: return linux_libc == LINUX_LIBC_MUSL ? "riscv32-unknown-linux-musl" : "riscv32-unknown-linux";
|
||||
case ELF_RISCV32: return "riscv32-unknown-elf";
|
||||
case LINUX_RISCV64: return linux_libc == LINUX_LIBC_MUSL ? "riscv64-unknown-linux-musl" : "riscv64-unknown-linux";
|
||||
case ELF_RISCV64: return "riscv64-unknown-elf";
|
||||
case ELF_XTENSA: return "xtensa-unknown-elf";
|
||||
case WASM32: return "wasm32-unknown-unknown";
|
||||
case WASM64: return "wasm64-unknown-unknown";
|
||||
case ARCH_OS_TARGET_DEFAULT: UNREACHABLE;
|
||||
}
|
||||
UNREACHABLE;
|
||||
};
|
||||
|
||||
static bool arch_is_supported(ArchType arch)
|
||||
@@ -1323,6 +1329,7 @@ static EnvironmentType environment_type_from_llvm_string(StringSlice env)
|
||||
}
|
||||
}
|
||||
|
||||
INFO_LOG("Platform Environment: %s", env.ptr);
|
||||
#define STRCASE(_str, _arch) if (slice_strcmp(env, _str)) return _arch;
|
||||
STRCASE("gnu", ENV_TYPE_GNU)
|
||||
STRCASE("gnuabin32", ENV_TYPE_GNUABIN32)
|
||||
@@ -2139,7 +2146,7 @@ void target_setup(BuildTarget *target)
|
||||
}
|
||||
#endif
|
||||
|
||||
compiler.platform.target_triple = arch_to_target_triple[target->arch_os_target];
|
||||
compiler.platform.target_triple = arch_to_target_triple(target->arch_os_target, target->linuxpaths.libc);
|
||||
ASSERT(compiler.platform.target_triple);
|
||||
|
||||
compiler.platform.alloca_address_space = 0;
|
||||
|
||||
@@ -36,7 +36,7 @@ ArchType hostinfo_arch_type(void)
|
||||
#elif defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) || defined(__ppc__) || defined(__PPC__) || defined(_ARCH_PPC)
|
||||
return ARCH_TYPE_PPC;
|
||||
#elif defined(__sparc__) || defined(__sparc)
|
||||
return ARCH_UNSUPPORTED
|
||||
return ARCH_UNSUPPORTED;
|
||||
#else
|
||||
return ARCH_TYPE_UNKNOWN;
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user