Skip to content

Commit de31e5a

Browse files
committed
picocrt: Add a 'none' variant
This builds an empty object file so that you can pass '--crt0=none' while linking and skip the picolibc-specific startup code. Signed-off-by: Keith Packard <[email protected]>
1 parent fd94dc8 commit de31e5a

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

picocrt/crt0-none.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* SPDX-License-Identifier: BSD-3-Clause
3+
*
4+
* Copyright © 2024 Keith Packard
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions
8+
* are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright
11+
* notice, this list of conditions and the following disclaimer.
12+
*
13+
* 2. Redistributions in binary form must reproduce the above
14+
* copyright notice, this list of conditions and the following
15+
* disclaimer in the documentation and/or other materials provided
16+
* with the distribution.
17+
*
18+
* 3. Neither the name of the copyright holder nor the names of its
19+
* contributors may be used to endorse or promote products derived
20+
* from this software without specific prior written permission.
21+
*
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26+
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27+
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28+
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31+
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
33+
* OF THE POSSIBILITY OF SUCH DAMAGE.
34+
*/
35+
36+
/*
37+
* This file is intentionally empty so that it generates no code at
38+
* all for the 'none' crt variant
39+
*/

picocrt/meson.build

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#
3535

3636
src_picocrt = []
37+
src_picocrt_none = files('crt0-none.c')
3738

3839
machine_dir = 'machine' / host_cpu_family
3940
picocrt_march_add=''
@@ -64,25 +65,30 @@ foreach target : targets
6465
crt_hosted_name = 'crt0-hosted.o'
6566
crt_minimal_name = 'crt0-minimal.o'
6667
crt_semihost_name = 'crt0-semihost.o'
68+
crt_none_name = 'crt0-none.o'
6769
libcrt_name = 'crt0'
6870
libcrt_hosted_name = 'crt0-hosted'
6971
libcrt_minimal_name = 'crt0-minimal'
7072
libcrt_semihost_name = 'crt0-semihost'
73+
libcrt_none_name = 'crt0-none'
7174
else
7275
crt_name = join_paths(target, 'crt0.o')
7376
crt_hosted_name = join_paths(target, 'crt0-hosted.o')
7477
crt_minimal_name = join_paths(target, 'crt0-minimal.o')
7578
crt_semihost_name = join_paths(target, 'crt0-semihost.o')
79+
crt_none_name = join_paths(target, 'crt0-none.o')
7680
libcrt_name = join_paths(target, 'libcrt0')
7781
libcrt_hosted_name = join_paths(target, 'libcrt0-hosted')
7882
libcrt_minimal_name = join_paths(target, 'libcrt0-minimal')
7983
libcrt_semihost_name = join_paths(target, 'libcrt0-semihost')
84+
libcrt_none_name = join_paths(target, 'libcrt0-none')
8085
endif
8186

8287
crt0_name = 'crt0' + target
8388
crt0_hosted_name = 'crt0_hosted' + target
8489
crt0_minimal_name = 'crt0_minimal' + target
8590
crt0_semihost_name = 'crt0_semihost' + target
91+
crt0_none_name = 'crt0_none' + target
8692

8793
_c_args = value[1] + arg_fnobuiltin + ['-ffreestanding']
8894
_link_args = value[1] + ['-r', '-ffreestanding']
@@ -185,4 +191,19 @@ foreach target : targets
185191
c_args : value[1] + ['-DCRT0_EXIT', '-DCRT0_SEMIHOST'])
186192
endif
187193
endif
194+
195+
# The 'none' variant is completely empty
196+
_crt = executable(crt_none_name,
197+
src_picocrt_none,
198+
include_directories : inc,
199+
install : true,
200+
install_dir : instdir,
201+
c_args : _c_args,
202+
link_args : _link_args)
203+
204+
set_variable(crt0_none_name,
205+
_crt.extract_objects(src_picocrt_none)
206+
)
207+
208+
188209
endforeach

0 commit comments

Comments
 (0)