Skip to content

Commit 5e16bb5

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 2e55ad9 commit 5e16bb5

File tree

5 files changed

+52
-47
lines changed

5 files changed

+52
-47
lines changed

sw/device/lib/base/BUILD

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ load("@bazel_skylib//lib:dicts.bzl", "dicts")
1515

1616
package(default_visibility = ["//visibility:public"])
1717

18+
filegroup(
19+
name = "doc_files",
20+
srcs = ["//sw/device/lib/base/freestanding:doc_files"],
21+
)
22+
1823
dual_cc_library(
1924
name = "crc32",
2025
srcs = dual_inputs(
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
@@ -53,27 +53,3 @@ subdirectory(
5353
parent = ":root",
5454
path = "lib/clang/16/include",
5555
)
56-
57-
subdirectory(
58-
name = "riscv32-unknown-elf-include",
59-
parent = ":root",
60-
path = "riscv32-unknown-elf/include",
61-
)
62-
63-
subdirectory(
64-
name = "cxx-include",
65-
parent = ":root",
66-
path = "riscv32-unknown-elf/include/c++/10.2.0",
67-
)
68-
69-
subdirectory(
70-
name = "cxx-backward",
71-
parent = ":root",
72-
path = "riscv32-unknown-elf/include/c++/10.2.0/backward",
73-
)
74-
75-
subdirectory(
76-
name = "cxx-riscv32-unknown-elf",
77-
parent = ":root",
78-
path = "riscv32-unknown-elf/include/c++/10.2.0/riscv32-unknown-elf",
79-
)

toolchain/BUILD

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ cc_toolchain(
6363
":arch_rv32imc",
6464
":arch_rv32imcb",
6565
":abi",
66-
":sys_spec",
6766
":warnings",
6867
":reproducible",
6968
":symbol_garbage_collection",
@@ -246,27 +245,15 @@ cc_args(
246245
"-isystem",
247246
"{clang-include}",
248247
"-isystem",
249-
"{riscv32-include}",
250-
"-isystem",
251-
"{cxx-include}",
252-
"-isystem",
253-
"{cxx-backward}",
254-
"-isystem",
255-
"{cxx-riscv32}",
248+
"{freestanding}",
256249
],
257250
data = [
258-
"@lowrisc_rv32imcb_toolchain//:cxx-backward",
259-
"@lowrisc_rv32imcb_toolchain//:cxx-include",
260-
"@lowrisc_rv32imcb_toolchain//:cxx-riscv32-unknown-elf",
251+
"//sw/device/lib/base/freestanding",
261252
"@lowrisc_rv32imcb_toolchain//:lib-clang-include",
262-
"@lowrisc_rv32imcb_toolchain//:riscv32-unknown-elf-include",
263253
],
264254
format = {
265255
"clang-include": "@lowrisc_rv32imcb_toolchain//:lib-clang-include",
266-
"riscv32-include": "@lowrisc_rv32imcb_toolchain//:riscv32-unknown-elf-include",
267-
"cxx-include": "@lowrisc_rv32imcb_toolchain//:cxx-include",
268-
"cxx-backward": "@lowrisc_rv32imcb_toolchain//:cxx-backward",
269-
"cxx-riscv32": "@lowrisc_rv32imcb_toolchain//:cxx-riscv32-unknown-elf",
256+
"freestanding": "//sw/device/lib/base/freestanding",
270257
},
271258
)
272259

@@ -476,17 +463,11 @@ cc_args_list(
476463
],
477464
)
478465

479-
cc_args(
480-
name = "sys_spec",
481-
actions = ["@rules_cc//cc/toolchains/actions:link_actions"],
482-
args = ["-lnosys"],
483-
)
484-
485466
cc_args(
486467
name = "constructor_destructor",
487468
actions = ["@rules_cc//cc/toolchains/actions:compile_actions"],
488469
args = [
489-
# Indicate that this program may not neccesarily be able to use standard system calls.
470+
# Indicate that this program may not necessarily be able to use standard system calls.
490471
"-ffreestanding",
491472
# Instantiate global variables only once.
492473
"-fno-common",

0 commit comments

Comments
 (0)