Skip to content

Commit 39523a0

Browse files
authored
Do not default to linking crt0 when using crt0-semihosting (#460)
* Do not default to linking crt0 when using crt0-semihosting This commit adds the -nostartfiles option to tests using semihosting. This is in response to a recent change in clang which modified the driver to include crt0.o in the link: llvm/llvm-project#101258 While the change to clang removes the need to include the crt0 library directly, the tests using semihosting need to link against a different crt0 library. Therefore the new default behavior needs to be suppressed in these cases, which can be done by adding the -nostartfiles option. * Also remove -lcrt0 from make.bat
1 parent fd450a3 commit 39523a0

File tree

17 files changed

+23
-20
lines changed

17 files changed

+23
-20
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1073,7 +1073,7 @@ Hard-float library with target triple \"${target_triple}\" must end \"-eabihf\""
10731073

10741074
get_runtimes_flags("${directory}" "${flags}")
10751075

1076-
set(compiler_rt_test_flags "${runtimes_flags} -fno-exceptions -fno-rtti -lcrt0-semihost -lsemihost -T picolibcpp.ld")
1076+
set(compiler_rt_test_flags "${runtimes_flags} -fno-exceptions -fno-rtti -nostartfiles -lcrt0-semihost -lsemihost -T picolibcpp.ld")
10771077
if(variant STREQUAL "armv6m_soft_nofp")
10781078
set(compiler_rt_test_flags "${compiler_rt_test_flags} -fomit-frame-pointer")
10791079
endif()

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ To use the toolchain, on the command line you need to provide the following opti
8787
* The FPU to use.
8888
* Disabling/enabling C++ exceptions and RTTI.
8989
* The C runtime library: either `crt0` or `crt0-semihost`.
90+
`crt0` will be linked automatically, but this can be suppressed
91+
with the `-nostartfiles` option so that `crt0-semihost` can be used.
9092
* The semihosting library, if using `crt0-semihost`.
9193
* A [linker script](
9294
https://sourceware.org/binutils/docs/ld/Scripts.html) specified with `-T`.
@@ -102,6 +104,7 @@ $ clang \
102104
-mfpu=none \
103105
-fno-exceptions \
104106
-fno-rtti \
107+
-nostartfiles \
105108
-lcrt0-semihost \
106109
-lsemihost \
107110
-T picolibc.ld \
@@ -130,6 +133,7 @@ $ clang \
130133
-mfpu=none \
131134
-fno-exceptions \
132135
-fno-rtti \
136+
-nostartfiles \
133137
-lcrt0-semihost \
134138
-lsemihost \
135139
-T picolibc.ld \

docs/migrating.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ however uses different command line options to control selection of semihosting.
8888

8989
|Use case|GNU options|LLVM options|
9090
|--------|-----------|------------|
91-
|No semihosting|`--specs=nosys.specs`|`-lcrt0`|
92-
|Semihosting|`--specs=rdimon.specs`|`-lcrt0-semihost -lsemihost`|
91+
|No semihosting|`--specs=nosys.specs`|
92+
|Semihosting|`--specs=rdimon.specs`|`-nostartfiles -lcrt0-semihost -lsemihost`|
9393
|Newlib-nano|`--specs=nano.specs`|Not available: `picolibc` is an equivalent of `newlib-nano`.
9494

9595
## Linker

packagetest/hello.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -T %S/Inputs/microbit.ld %s -o %t.out
1+
// RUN: %clang --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -nostartfiles -lcrt0-semihost -lsemihost -T %S/Inputs/microbit.ld %s -o %t.out
22
// RUN: qemu-system-arm -M microbit -semihosting -nographic -device loader,file=%t.out 2>&1 | FileCheck %s
33

44
#include <stdio.h>

packagetest/hello.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clangxx --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -T %S/Inputs/microbit.ld %s -o %t.out
1+
// RUN: %clangxx --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -nostartfiles -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -T %S/Inputs/microbit.ld %s -o %t.out
22
// RUN: qemu-system-arm -M microbit -semihosting -nographic -device loader,file=%t.out 2>&1 | FileCheck %s
33

44
// Include as many C++17 headers as possible.

samples/Makefile.conf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ endif
2222
MICROBIT_TARGET=--target=armv6m-none-eabi -march=armv6m -mfpu=none -mfloat-abi=soft
2323
AARCH64_TARGET=--target=aarch64-none-elf
2424

25-
CRT=-lcrt0
26-
CRT_SEMIHOST=-lcrt0-semihost -lsemihost
25+
CRT_SEMIHOST=-nostartfiles -lcrt0-semihost -lsemihost
2726

2827
CPP_FLAGS=-fno-exceptions -fno-rtti

samples/src/baremetal-semihosting-aarch64/make.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ if exist hello.img del /q hello.img
4949
@exit /B 1
5050

5151
:build_fn
52-
%BIN_PATH%\clang.exe --target=aarch64-none-elf -lcrt0-semihost -lsemihost -g -T ..\..\ldscripts\raspi3b.ld -o hello.elf hello.c
52+
%BIN_PATH%\clang.exe --target=aarch64-none-elf -nostartfiles -lcrt0-semihost -lsemihost -g -T ..\..\ldscripts\raspi3b.ld -o hello.elf hello.c
5353
%BIN_PATH%\llvm-objcopy.exe -O binary hello.elf hello.img
5454
@exit /B

samples/src/baremetal-semihosting/make.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ if exist hello.hex del /q hello.hex
4949
@exit /B 1
5050

5151
:build_fn
52-
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -g -T ..\..\ldscripts\microbit.ld -o hello.elf hello.c
52+
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -nostartfiles -lcrt0-semihost -lsemihost -g -T ..\..\ldscripts\microbit.ld -o hello.elf hello.c
5353
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
5454
@exit /B

samples/src/baremetal-uart/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ include ../../Makefile.conf
2020
build: hello.elf
2121

2222
hello.elf: *.c
23-
$(BIN_PATH)/clang $(MICROBIT_TARGET) $(CRT) -g -T ../../ldscripts/microbit.ld -o hello.elf $^
23+
$(BIN_PATH)/clang $(MICROBIT_TARGET) -g -T ../../ldscripts/microbit.ld -o hello.elf $^
2424

2525
%.hex: %.elf
2626
$(BIN_PATH)/llvm-objcopy -O ihex $< $@

samples/src/baremetal-uart/make.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ if exist hello.hex del /q hello.hex
4949
@exit /B 1
5050

5151
:build_fn
52-
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0 -g -T ..\..\ldscripts\microbit.ld -o hello.elf hello.c
52+
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -g -T ..\..\ldscripts\microbit.ld -o hello.elf hello.c
5353
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
5454
@exit /B

samples/src/cpp-baremetal-semihosting-cfi/make.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ if exist hello.hex del /q hello.hex
5757

5858
:build_fn
5959
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -fno-exceptions -fno-rtti -flto -fsanitize=cfi -fvisibility=hidden -fno-sanitize-ignorelist -g -c hello.cpp
60-
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -flto -T ..\..\ldscripts\microbit.ld -g -o hello.elf hello.o
60+
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -nostartfiles -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -flto -T ..\..\ldscripts\microbit.ld -g -o hello.elf hello.o
6161
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
6262
@exit /B
6363

6464
:build_no_cfi_fn
6565
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -fno-exceptions -fno-rtti -flto -g -c hello.cpp
66-
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -flto -T ..\..\ldscripts\microbit.ld -g -o hello.elf hello.o
66+
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -nostartfiles -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -flto -T ..\..\ldscripts\microbit.ld -g -o hello.elf hello.o
6767
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
6868
@exit /B

samples/src/cpp-baremetal-semihosting-prof/make.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ if exist proflib.o del /q proflib.o
5555

5656
:build_fn
5757
%BIN_PATH%\clang.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -g -c proflib.c
58-
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -g -T ..\..\ldscripts\microbit.ld -fprofile-instr-generate -fcoverage-mapping -o hello.elf hello.cpp proflib.o
58+
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -nostartfiles -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -g -T ..\..\ldscripts\microbit.ld -fprofile-instr-generate -fcoverage-mapping -o hello.elf hello.cpp proflib.o
5959
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
6060
@exit /B

samples/src/cpp-baremetal-semihosting-ubsan/make.bat

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ if exist hello.hex del /q hello.hex
5555
@exit /B 1
5656

5757
:build_fn
58-
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti --std=c++17 -fsanitize=undefined -fsanitize-minimal-runtime -g -T ../../ldscripts/microbit.ld -o hello.elf *.cpp
58+
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -nostartfiles -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti --std=c++17 -fsanitize=undefined -fsanitize-minimal-runtime -g -T ../../ldscripts/microbit.ld -o hello.elf *.cpp
5959
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
6060
@exit /B
6161

6262
:build_trap_fn
63-
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti --std=c++17 -fsanitize=undefined -fsanitize-trap=all -g -T ../../ldscripts/microbit.ld -o hello.elf *.cpp
63+
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -nostartfiles -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti --std=c++17 -fsanitize=undefined -fsanitize-trap=all -g -T ../../ldscripts/microbit.ld -o hello.elf *.cpp
6464
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
6565
@exit /B

samples/src/cpp-baremetal-semihosting/make.bat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@ if exist hello.hex del /q hello.hex
4949
@exit /B 1
5050

5151
:build_fn
52-
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -g -T ..\..\ldscripts\microbit.ld -o hello.elf hello.cpp
52+
%BIN_PATH%\clang++.exe --target=armv6m-none-eabi -mfloat-abi=soft -march=armv6m -mfpu=none -nostartfiles -lcrt0-semihost -lsemihost -fno-exceptions -fno-rtti -g -T ..\..\ldscripts\microbit.ld -o hello.elf hello.cpp
5353
%BIN_PATH%\llvm-objcopy.exe -O ihex hello.elf hello.hex
5454
@exit /B

test-support/llvm-libc++-picolibc.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ config.substitutions.append(('%{link_flags}',
2727
' -nostdlib++ -L %{lib-dir}'
2828
' -lc++ -lc++abi'
2929
' -nostdlib -L %{libc-lib}'
30-
' -lc -lm -lclang_rt.builtins -lsemihost -lcrt0-semihost'
30+
' -lc -lm -lclang_rt.builtins -lsemihost -nostartfiles -lcrt0-semihost'
3131
' -T %{libc-linker-script}'
3232
))
3333
config.substitutions.append(('%{exec}',

test-support/llvm-libc++abi-picolibc.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ config.substitutions.append(('%{link_flags}',
1919
' -nostdlib++ -L %{lib}'
2020
' -lc++ -lc++abi'
2121
' -nostdlib -L %{libc-lib}'
22-
' -lc -lm -lclang_rt.builtins -lsemihost -lcrt0-semihost'
22+
' -lc -lm -lclang_rt.builtins -lsemihost -nostartfiles -lcrt0-semihost'
2323
' -T %{libc-linker-script}'
2424
))
2525
config.substitutions.append(('%{exec}',

test-support/llvm-libunwind-picolibc.cfg.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ config.substitutions.append(('%{link_flags}',
3232
' -nostdlib++ -L %{lib}'
3333
' -lc++ -lc++abi -lunwind'
3434
' -nostdlib -L %{libc-lib}'
35-
' -lc -lm -lclang_rt.builtins -lsemihost -lcrt0-semihost'
35+
' -lc -lm -lclang_rt.builtins -lsemihost -nostartfiles -lcrt0-semihost'
3636
' -T %{libc-linker-script}'
3737
))
3838
config.substitutions.append(('%{exec}',

0 commit comments

Comments
 (0)