Skip to content

Commit d6be5b8

Browse files
committed
[toolchain] Use freestanding environment
Remove the use of headers provided by Newlib and GCC. Instead, use a freestanding environment provided by a combination of Clang + OpenTitan. Also, don't link again nosys, as we aren't linking agaist Newlib, nor do we want to. Signed-off-by: Luís Marques <[email protected]>
1 parent 6f041a8 commit d6be5b8

File tree

5 files changed

+48
-48
lines changed

5 files changed

+48
-48
lines changed

sw/device/lib/base/BUILD

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ package(default_visibility = ["//visibility:public"])
1818

1919
filegroup(
2020
name = "doc_files",
21-
srcs = glob(["**/*.md"]),
21+
srcs = glob(["**/*.md"]) + ["//sw/device/lib/base/freestanding:doc_files"],
2222
)
2323

2424
dual_cc_library(
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Copyright lowRISC contributors (OpenTitan project).
2+
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
# SPDX-License-Identifier: Apache-2.0
4+
5+
load("@bazel_skylib//rules/directory:directory.bzl", "directory")
6+
7+
package(default_visibility = ["//visibility:public"])
8+
9+
directory(
10+
name = "freestanding",
11+
srcs = glob(["**"]),
12+
)
13+
14+
filegroup(
15+
name = "doc_files",
16+
srcs = glob(["**/*.md"]),
17+
)
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright lowRISC contributors (OpenTitan project).
2+
// Licensed under the Apache License, Version 2.0, see LICENSE for details.
3+
// SPDX-License-Identifier: Apache-2.0
4+
5+
#ifndef OPENTITAN_SW_DEVICE_LIB_BASE_FREESTANDING_STRING_H_
6+
#define OPENTITAN_SW_DEVICE_LIB_BASE_FREESTANDING_STRING_H_
7+
8+
#include <stddef.h>
9+
10+
/**
11+
* @file
12+
* @brief C library string handling (Freestanding)
13+
*
14+
* This header implements the string.h standard header, as required by C24 S4p7,
15+
* and to the extent implemented by `sw/device/lib/base/memory.h`.
16+
*
17+
*/
18+
19+
void *memcpy(void *dest, const void *src, size_t len);
20+
void *memset(void *dest, int value, size_t len);
21+
int memcmp(const void *lhs, const void *rhs, size_t len);
22+
int memrcmp(const void *lhs, const void *rhs, size_t len);
23+
void *memchr(const void *ptr, int value, size_t len);
24+
void *memrchr(const void *ptr, int value, size_t len);
25+
26+
#endif // OPENTITAN_SW_DEVICE_LIB_BASE_FREESTANDING_STRING_H_

third_party/lowrisc/BUILD.lowrisc_rv32imcb_toolchain.bazel

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -41,27 +41,3 @@ subdirectory(
4141
parent = ":root",
4242
path = "lib/clang/16/include",
4343
)
44-
45-
subdirectory(
46-
name = "riscv32-unknown-elf-include",
47-
parent = ":root",
48-
path = "riscv32-unknown-elf/include",
49-
)
50-
51-
subdirectory(
52-
name = "cxx-include",
53-
parent = ":root",
54-
path = "riscv32-unknown-elf/include/c++/10.2.0",
55-
)
56-
57-
subdirectory(
58-
name = "cxx-backward",
59-
parent = ":root",
60-
path = "riscv32-unknown-elf/include/c++/10.2.0/backward",
61-
)
62-
63-
subdirectory(
64-
name = "cxx-riscv32-unknown-elf",
65-
parent = ":root",
66-
path = "riscv32-unknown-elf/include/c++/10.2.0/riscv32-unknown-elf",
67-
)

toolchain/BUILD

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ cc_toolchain(
4141
":arch_rv32imc",
4242
":arch_rv32imcb",
4343
":abi",
44-
":sys_spec",
4544
":warnings",
4645
":reproducible",
4746
":symbol_garbage_collection",
@@ -220,27 +219,15 @@ cc_args(
220219
"-isystem",
221220
"{clang-include}",
222221
"-isystem",
223-
"{riscv32-include}",
224-
"-isystem",
225-
"{cxx-include}",
226-
"-isystem",
227-
"{cxx-backward}",
228-
"-isystem",
229-
"{cxx-riscv32}",
222+
"{freestanding}",
230223
],
231224
data = [
232-
"@lowrisc_rv32imcb_toolchain//:cxx-backward",
233-
"@lowrisc_rv32imcb_toolchain//:cxx-include",
234-
"@lowrisc_rv32imcb_toolchain//:cxx-riscv32-unknown-elf",
225+
"//sw/device/lib/base/freestanding",
235226
"@lowrisc_rv32imcb_toolchain//:lib-clang-include",
236-
"@lowrisc_rv32imcb_toolchain//:riscv32-unknown-elf-include",
237227
],
238228
format = {
239229
"clang-include": "@lowrisc_rv32imcb_toolchain//:lib-clang-include",
240-
"riscv32-include": "@lowrisc_rv32imcb_toolchain//:riscv32-unknown-elf-include",
241-
"cxx-include": "@lowrisc_rv32imcb_toolchain//:cxx-include",
242-
"cxx-backward": "@lowrisc_rv32imcb_toolchain//:cxx-backward",
243-
"cxx-riscv32": "@lowrisc_rv32imcb_toolchain//:cxx-riscv32-unknown-elf",
230+
"freestanding": "//sw/device/lib/base/freestanding",
244231
},
245232
)
246233

@@ -399,17 +386,11 @@ cc_args_list(
399386
],
400387
)
401388

402-
cc_args(
403-
name = "sys_spec",
404-
actions = ["@rules_cc//cc/toolchains/actions:link_actions"],
405-
args = ["-lnosys"],
406-
)
407-
408389
cc_args(
409390
name = "constructor_destructor",
410391
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
411392
args = [
412-
# Indicate that this program may not neccesarily be able to use standard system calls.
393+
# Indicate that this program may not necessarily be able to use standard system calls.
413394
"-ffreestanding",
414395
# Instantiate global variables only once.
415396
"-fno-common",

0 commit comments

Comments
 (0)