Skip to content

Commit

Permalink
update newlib to try to match libc++
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Nov 23, 2023
1 parent 35fa3b9 commit ba822da
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
4 changes: 2 additions & 2 deletions newlib/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ RUN apt install -y git build-essential wget rsync zip

# Clone the libtock-c source so we can use the build scripts
RUN git clone https://github.com/tock/libtock-c --depth 1 -b make-precompiled
RUN cd libtock-c && git fetch && git checkout 818c828338b2a349e4d3e8969f6ccc0817bab470
RUN cd libtock-c && git fetch && git checkout 35fa3b90d2beec1a9d3a7bacbb9907f9e4461840

# Actually build the toolchain
RUN cd libtock-c/newlib && make
RUN cd libtock-c/newlib && make NEWLIB_VERSION=4.2.0.20211231
22 changes: 12 additions & 10 deletions newlib/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
NEWLIB_VERSION ?= 4.2.0.20211231

all: rebuild-newlib

ifeq ($(NEWLIB_VERSION),)
$(error Need to set the NEWLIB_VERSION variable to choose which to build.)
endif

# Determine which RISC-V toolchain is installed.
ifneq (,$(shell which riscv64-none-elf-gcc 2>/dev/null))
TOOLCHAIN_rv32i := riscv64-none-elf
Expand All @@ -19,7 +21,7 @@ endif

newlib-$(NEWLIB_VERSION).tar.gz:
@echo "Downloading newlib source $(@F)"
@wget -q -O $@ ftp://sourceware.org/pub/newlib/newlib-$(NEWLIB_VERSION).tar.gz
@wget -q -O $@ https://sourceware.mirror.garr.it/newlib/newlib-$(NEWLIB_VERSION).tar.gz

newlib-$(NEWLIB_VERSION): newlib-$(NEWLIB_VERSION).tar.gz
@echo "Extracting $(<F)"
Expand All @@ -30,28 +32,28 @@ rebuild-newlib: newlib-$(NEWLIB_VERSION)
@echo ""
@echo "=== BEGINNING ARM BUILD =========================="
@echo ""
@rm -rf newlib-arm-$(NEWLIB_VERSION)-out
@mkdir -p newlib-arm-$(NEWLIB_VERSION)-out
@mkdir -p newlib-arm-$(NEWLIB_VERSION)-install
@echo "Entering directory newlib-arm-$(NEWLIB_VERSION)-out"
cd newlib-arm-$(NEWLIB_VERSION)-out; ../build-arm.sh ../$<
cd newlib-arm-$(NEWLIB_VERSION)-out; ../build-arm.sh ../$< ../newlib-arm-$(NEWLIB_VERSION)-install
@echo ""
@echo "=== BEGINNING RISC-V BUILD ======================="
@echo ""
@rm -rf newlib-riscv-$(NEWLIB_VERSION)-out
@mkdir -p newlib-riscv-$(NEWLIB_VERSION)-out
@mkdir -p newlib-riscv-$(NEWLIB_VERSION)-install
@echo "Entering directory newlib-riscv-$(NEWLIB_VERSION)-out"
cd newlib-riscv-$(NEWLIB_VERSION)-out; ../build-riscv.sh ../$< $(TOOLCHAIN_rv32i)
cd newlib-riscv-$(NEWLIB_VERSION)-out; ../build-riscv.sh ../$< ../newlib-riscv-$(NEWLIB_VERSION)-install $(TOOLCHAIN_rv32i)
@echo ""
@echo "=== PACKAGING NEWLIB ARTIFACTS ==================="
@echo ""
@mkdir -p libtock-newlib-$(NEWLIB_VERSION)/thumb
@mkdir -p libtock-newlib-$(NEWLIB_VERSION)/arm
@mkdir -p libtock-newlib-$(NEWLIB_VERSION)/riscv
@cp -r newlib-$(NEWLIB_VERSION)/newlib/libc/include libtock-newlib-$(NEWLIB_VERSION)/headers
@rsync -ram --exclude='/*/*/*/*/' --include='libm.a' --include='libc.a' --include='*/' --exclude='*' newlib-arm-$(NEWLIB_VERSION)-out/arm-none-eabi/thumb/ libtock-newlib-$(NEWLIB_VERSION)/thumb/
@rsync -ram --exclude='/*/*/*/*/' --include='libm.a' --include='libc.a' --include='*/' --exclude='*' newlib-arm-$(NEWLIB_VERSION)-out/arm-none-eabi/thumb/ libtock-newlib-$(NEWLIB_VERSION)/arm/
@rsync -ram --exclude='/*/*/*/*/' --include='libm.a' --include='libc.a' --include='*/' --exclude='*' newlib-riscv-$(NEWLIB_VERSION)-out/$(TOOLCHAIN_rv32i)/ libtock-newlib-$(NEWLIB_VERSION)/riscv/
@patch -p1 < newlib-$(NEWLIB_VERSION).patch
@zip -r libtock-newlib-$(NEWLIB_VERSION).zip libtock-newlib-$(NEWLIB_VERSION)
@echo ""
@echo "=== FINISHED NEWLIB ZIP ==================="
@echo "=== FINISHED NEWLIB ZIP =========================="
@echo ""
@sha256sum libtock-newlib-$(NEWLIB_VERSION).zip
5 changes: 4 additions & 1 deletion newlib/build-arm.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env bash

NEWLIB_SRC_DIR=$1
NEWLIB_INSTALL_DIR=$2

# We want to end up with newlib compiled for at least the `v6-m/nofp`,
# `v7-m/nofp`, and `v7e-m/nofp` architectures. For that to happen the
Expand Down Expand Up @@ -30,6 +31,8 @@ $NEWLIB_SRC_DIR/configure --target=arm-none-eabi \
--disable-newlib-unbuf-stream-opt \
--enable-lite-exit \
--enable-newlib-global-atexit \
--enable-newlib-nano-formatted-io
--enable-newlib-nano-formatted-io \
--prefix=`realpath $NEWLIB_INSTALL_DIR`

make -j$(nproc) CFLAGS_FOR_TARGET='-g -Os -ffunction-sections -fdata-sections -fPIC -msingle-pic-base -mno-pic-data-is-text-relative'
make install
7 changes: 5 additions & 2 deletions newlib/build-riscv.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#!/usr/bin/env bash

NEWLIB_SRC_DIR=$1
TARGET=$2
NEWLIB_INSTALL_DIR=$2
TARGET=$3

$NEWLIB_SRC_DIR/configure --target=$TARGET \
--disable-newlib-supplied-syscalls \
Expand All @@ -14,6 +15,8 @@ $NEWLIB_SRC_DIR/configure --target=$TARGET \
--disable-newlib-unbuf-stream-opt \
--enable-lite-exit \
--enable-newlib-global-atexit \
--enable-newlib-nano-formatted-io
--enable-newlib-nano-formatted-io \
--prefix=`realpath $NEWLIB_INSTALL_DIR`

make -j$(nproc) CFLAGS_FOR_TARGET='-g -Os -ffunction-sections -fdata-sections'
make install

0 comments on commit ba822da

Please sign in to comment.