Skip to content

Commit 34af15c

Browse files
committed
chore: switch to picolibc fork
1 parent 4daa971 commit 34af15c

6 files changed

Lines changed: 39 additions & 49 deletions

File tree

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "src/hyperlight_guest_bin/third_party/picolibc"]
22
path = src/hyperlight_guest_bin/third_party/picolibc
3-
url = https://github.com/picolibc/picolibc.git
3+
url = https://github.com/andreiltd/picolibc-bsd.git
44
shallow = true

NOTICE.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ permissive licenses. The full license details for all files are
5555
documented in the COPYING.picolibc and COPYING.NEWLIB files in the
5656
picolibc submodule at src/hyperlight_guest_bin/third_party/picolibc/.
5757

58-
Note: The picolibc submodule uses sparse checkout to exclude
59-
GPL/AGPL-licensed test and script files that are not needed for
60-
building. Only BSD/MIT/permissive-licensed source files are included.
58+
Note: The picolibc submodule uses the picolibc-bsd fork
59+
(https://github.com/hyperlight-dev/picolibc-bsd), which is a redistribution
60+
with all copyleft-licensed files removed from the tree and history.
61+
Only BSD/MIT/permissive-licensed source files are present.
6162

docs/picolibc.md

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ The picolibc integration is controlled by the `libc` feature flag on the
1212
script compiles picolibc from source using the vendored submodule at
1313
`src/hyperlight_guest_bin/third_party/picolibc`.
1414

15-
The build uses a sparse checkout to exclude GPL/AGPL-licensed test and script
16-
files and only BSD/MIT/permissive-licensed source files are included. See
17-
`NOTICE.txt` for full licensing details.
15+
The submodule points to [picolibc-bsd](https://github.com/hyperlight-dev/picolibc-bsd),
16+
a redistribution of picolibc with all copyleft-licensed files (GPL/AGPL)
17+
removed from the tree and history. Only BSD/MIT/permissive-licensed source
18+
files are present. See `NOTICE.txt` for full licensing details.
1819

1920
## Host Function Stubs
2021

@@ -63,33 +64,34 @@ The file list of picolibc sources to compile is maintained in `build_files.rs`.
6364

6465
To update picolibc to a new version:
6566

66-
1. Update the submodule:
67+
1. Import new upstream commits into the [picolibc-bsd](https://github.com/hyperlight-dev/picolibc-bsd) fork.
68+
See `picolibc-bsd` README.md for instructions how to do that.
69+
70+
2. Update the submodule in hyperlight:
6771
```bash
6872
cd src/hyperlight_guest_bin/third_party/picolibc
6973
git fetch origin
70-
git checkout <new-version-tag>
74+
git checkout <new-fork-tag>
7175
cd ../../../..
7276
git add src/hyperlight_guest_bin/third_party/picolibc
7377
```
7478

75-
2. Verify licensing: Check that no new GPL/AGPL-licensed source files
76-
have been added to the directories we compile. The sparse checkout
77-
(configured in `build.rs` `sparse_checkout()`) excludes `test/`,
78-
`scripts/`, and `COPYING.GPL2`, but review any new files.
79+
3. Verify licensing: The fork's CI runs scancode-toolkit to ensure no
80+
copyleft files are present. Review the CI results on the fork.
7981

80-
3. Update `build_files.rs`: Compare the file list against the new
82+
4. Update `build_files.rs`: Compare the file list against the new
8183
version's meson build files. Files may have been added, removed, or
8284
renamed. The meson build definitions in `libc/meson.build` and
8385
`libm/meson.build` (and their subdirectory `meson.build` files)
8486
are the source of truth for which files to compile.
8587

86-
4. Update version strings in `build.rs`: Update the `__PICOLIBC_VERSION__`,
88+
5. Update version strings in `build.rs`: Update the `__PICOLIBC_VERSION__`,
8789
`__PICOLIBC__`, `__PICOLIBC_MINOR__`, `__PICOLIBC_PATCHLEVEL__`,
8890
`_NEWLIB_VERSION`, and related defines in `gen_config_file()`.
8991

90-
5. Update `NOTICE.txt`: Bump the version number in the picolibc entry.
92+
6. Update `NOTICE.txt`: Bump the version number in the picolibc entry.
9193

92-
6. Build and test:
94+
7. Build and test:
9395
```bash
9496
just guests
9597
just test

src/hyperlight_guest_bin/build.rs

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ fn add_libm(build: &mut cc::Build, picolibc_dir: &Path, target: &str) -> Result<
309309
Ok(())
310310
}
311311

312-
fn sparse_checkout() -> Result<()> {
312+
fn init_submodule() -> Result<()> {
313313
let status = Command::new("git")
314314
.args(["submodule", "update", "--init"])
315315
.status()?;
@@ -318,30 +318,6 @@ fn sparse_checkout() -> Result<()> {
318318
bail!("git submodule update --init failed");
319319
}
320320

321-
// Exclude GPL/AGPL-licensed files from the picolibc submodule
322-
Command::new("git")
323-
.args([
324-
"-C",
325-
"third_party/picolibc",
326-
"sparse-checkout",
327-
"init",
328-
"--no-cone",
329-
])
330-
.status()?;
331-
332-
Command::new("git")
333-
.args([
334-
"-C",
335-
"third_party/picolibc",
336-
"sparse-checkout",
337-
"set",
338-
"**",
339-
"!test/**",
340-
"!scripts/**",
341-
"!COPYING.GPL2",
342-
])
343-
.status()?;
344-
345321
Ok(())
346322
}
347323

@@ -360,7 +336,7 @@ fn cargo_main() -> Result<()> {
360336
if cfg!(feature = "libc") {
361337
if !Path::new("third_party/picolibc/COPYING.picolibc").exists() {
362338
eprintln!("Setting up submodules");
363-
sparse_checkout().with_context(|| "failed to init picolibc submodule")?;
339+
init_submodule().with_context(|| "failed to init picolibc submodule")?;
364340
}
365341

366342
let picolibc_dir = PathBuf::from("third_party/picolibc");

src/hyperlight_guest_bin/src/libc.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ pub extern "C" fn write(fd: c_int, buf: *const c_void, count: usize) -> isize {
111111

112112
#[unsafe(no_mangle)]
113113
pub extern "C" fn _current_time(ts: *mut u64) -> c_int {
114+
if ts.is_null() {
115+
set_errno(EINVAL);
116+
return -1;
117+
}
118+
114119
let (secs, nanos) = current_time();
115120
let ts = unsafe { core::slice::from_raw_parts_mut(ts, 2) };
116121
ts[0] = secs;
Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
# Third Party Library Use
22

3-
This project makes use of the following third party libraries, each of which is contained in a subdirectory of `third_party` with a COPYRIGHT/LICENSE file in the root of the subdirectory. These libraries are used under the terms of their respective licenses. They are also listed in the NOTICE file in the root of the repository.
3+
This project makes use of the following third party libraries, each of which is contained in a
4+
subdirectory of `third_party` with a COPYRIGHT/LICENSE file in the root of the subdirectory. These
5+
libraries are used under the terms of their respective licenses. They are also listed in the NOTICE
6+
file in the root of the repository.
47

58
## picolibc
69

7-
[picolibc](https://github.com/picolibc/picolibc) is a C library designed for embedded systems, derived from newlib. It is included as a git submodule.
10+
[picolibc](https://github.com/picolibc/picolibc) is a C library designed for embedded systems,
11+
derived from newlib. It is included as a git submodule pointing to the
12+
[picolibc-bsd](https://github.com/hyperlight-dev/picolibc-bsd) fork.
813

914
- **Version**: 1.8.11
10-
- **License**: BSD-3-Clause (picolibc), with BSD/MIT-compatible licenses for newlib portions (see `COPYING.picolibc` and `COPYING.NEWLIB`)
15+
- **License**: BSD-3-Clause (picolibc), with BSD/MIT-compatible licenses for newlib portions (see
16+
`COPYING.picolibc` and `COPYING.NEWLIB`)
1117
- **Submodule path**: `third_party/picolibc`
1218

13-
The submodule uses sparse checkout to exclude GPL/AGPL-licensed files (`test/`, `scripts/`, `COPYING.GPL2`) that are not needed for building and are not compatible with the project's license.
14-
15-
Only the `newlib/` subtree is used by the build (libc and libm sources). Complex math (`complex/`) files from libm are intentionally excluded to reduce binary size.
19+
The submodule uses the picolibc-bsd fork, which is a redistribution of picolibc with all
20+
copyleft-licensed files (GPL/AGPL) removed from the tree and history. Only permissively-licensed
21+
source files are present.

0 commit comments

Comments
 (0)