From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [IPv6:2001:67c:2050:0:465::101]) by sourceware.org (Postfix) with ESMTPS id 1B45E3858D39 for ; Tue, 7 Mar 2023 11:13:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1B45E3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=aarsen.me Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=aarsen.me Received: from smtp2.mailbox.org (smtp2.mailbox.org [10.196.197.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4PWCVq3MSyz9sbw; Tue, 7 Mar 2023 12:13:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aarsen.me; s=MBO0001; t=1678187619; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=Y+krbNGkhCnMlZwWz3kySmhddknrTxfU8B1sG2wlczA=; b=rAkxSGkFM8qVWH4/8UfypnPvKTk1nBmnT9z3gkgx2EZyshOghaphHuEDDSMlBmDLkZXLx5 ouMG/YTVDtJBGzTyjvYDPNsLIR7TQbZEheINatNnvgsGIJQ8kyRrvsNuJfJnPdIuIWK7mH qXgYBgSpjCtzERuPnwAxuBg65Y2lBiaSXMMeo0lfKO8PpX9t9Wet7Tn3cYVnGMETW6y3Jq bG3CAvgkUBFglr5QCE/K3J/8hMnaM/SHUsk2u35QsWlMwwKgKXyb0KNt4pcy2eOis4T5p9 0G9Cr/JR7d3krDVsJ8ILNp+d/Sh2n8wyXujY5W4YQlV14NTi7ufrr7/tF7+sXg== References: <20230221233125.GA2142@raven.inka.de> <7eead147-36bf-9f31-da9b-be006efd8aa3@foss.arm.com> <20230306144047.GB2142@raven.inka.de> From: Arsen =?utf-8?Q?Arsenovi=C4=87?= To: Josef Wolf Cc: Richard Earnshaw , Jonathan Wakely , gcc-help@gcc.gnu.org Subject: Re: How to omit libc (newlib) on bare metal (freestanding)? Date: Tue, 07 Mar 2023 12:08:44 +0100 In-reply-to: <20230306144047.GB2142@raven.inka.de> Message-ID: <86v8jcx19c.fsf@aarsen.me> MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" X-Spam-Status: No, score=-5.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,KAM_INFOUSMEBIZ,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Josef Wolf writes: >> > > Do you mean you're trying to build GCC itself, or you're trying to b= uild >> > > your own program? > > I am trying to build my own program using GCC which I have built by mysel= f :) > >> > > Please show the full commands you're using >> > >=20 >> > > If you add -v to the gcc command it will show exactly what it's doin= g. > > Appended to the end of this post. > >> > Oh actually I see the problem. You're using -lgcc and your gcc was >> > configured to use newlib, so libgcc depends on newlib. > > I am irritated about that. I see that libgcc needs malloc() and friends. = But I > don't see why libgcc would need sbrk/write/close/lseek/read. > >> Whilst there are functions in libgcc that depend on newlib (not many and >> probably none that you'd need in this instance), I wouldn't have expected >> -lgcc to cause -lc to be added to the link set. > > Exactly. As a side-note: I provide my own implementations of memcpy() and > friends, So I don't see why gcc would need to pull them from > newlib. Especially when I explicitly provide all those fancy options I > mentioned above to prevent using any libraries. This is because libgcc was built with newlib. If you do not want newlib, I suggest configuring with --without-headers --without-newlib. I've also added some support code to that configuration recently, but I don't think it'll match your configuration. You might have to do some patching after that for your new target, specifically to set use_gcc_stdint=3Dprovide in config.gcc. Please try adding those two flags to configure and seeing where that goes. Have a lovely day! >> Josef, what is the *complete* command line that you issue when you link = the >> program? > > Here it comes: > > $ /usr/local/crossgcc/arm-none-eabi/bin/arm-none-eabi-gcc \ > lots.o of.o object.o files.o \ > -v -mcpu=3Dcortex-m4 -mthumb -mfpu=3Dfpv4-sp-d16 -mfloat-abi=3Dhard \ > -Tcubemx/STM32F429BITx_FLASH.ld -nostdlib -lm -lnosys -nolibc \ > -nodefaultlibs -nostartfiles -nostdlib -ffreestanding -static-libgcc \ > -Wl,-Map=3Dbuild/cubemx.map,--cref \ > -Wl,--gc-sections,--exclude-libs,libc.a \ > -o build/cubemx.elf > Using built-in specs. > COLLECT_GCC=3D/usr/local/crossgcc/arm-none-eabi/bin/arm-none-eabi-gcc > COLLECT_LTO_WRAPPER=3D/usr/local/crossgcc/arm-none-eabi/bin/../libexec/gc= c/arm-none-eabi/9.3.0/lto-wrapper > Target: arm-none-eabi > Configured with: /var/tmp/builds/crossgcc/src/gcc-9.3.0/configure --targe= t=3Darm-none-eabi --build=3Dx86_64-pc-linux-gnu --host=3Dx86_64-pc-linux-gn= u --enable-languages=3Dc,c++ --with-gnu-ld --with-gnu-as --with-newlib --wi= th-system-zlib --enable-commonbfdlib --enable-interwork --enable-install-li= bbfd --enable-plugins --enable-multilib --disable-nls --disable-shared --di= sable-libssp --nfp --gas -v --prefix=3D/usr/local/crossgcc/arm-none-eabi --= enable-languages=3Dc,c++ --with-pkgversion=3Dcrossgcc --disable-libstdcxx-v= erbose --enable-plugins --disable-decimal-float --disable-libffi --disable-= libgomp --disable-libmudflap --disable-libquadmath --disable-libstdcxx-pch = --disable-threads --disable-tls --with-headers=3Dyes --with-multilib-list= =3Drmprofile > Thread model: single > gcc version 9.3.0 (crossgcc) > COMPILER_PATH=3D/usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/arm-= none-eabi/9.3.0/:/usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/:/usr= /local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../.= ./arm-none-eabi/bin/ > LIBRARY_PATH=3D/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-= eabi/9.3.0/thumb/v7e-m+fp/hard/:/usr/local/crossgcc/arm-none-eabi/bin/../li= b/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard= /:/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/:/us= r/local/crossgcc/arm-none-eabi/bin/../lib/gcc/:/usr/local/crossgcc/arm-none= -eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/ > COLLECT_GCC_OPTIONS=3D'-v' '-mcpu=3Dcortex-m4' '-mthumb' '-mfpu=3Dfpv4-sp= -d16' '-mfloat-abi=3Dhard' '-T' 'cubemx/STM32F429BITx_FLASH.ld' '-nostdlib'= '-nolibc' '-nodefaultlibs' '-nostartfiles' '-nostdlib' '-ffreestanding' '-= static-libgcc' '-o' 'build/cubemx.elf' '-march=3Darmv7e-m+fp' > /usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/arm-none-eabi/9.3.0= /collect2 -plugin /usr/local/crossgcc/arm-none-eabi/bin/../libexec/gcc/arm-= none-eabi/9.3.0/liblto_plugin.so -plugin-opt=3D/usr/local/crossgcc/arm-none= -eabi/bin/../libexec/gcc/arm-none-eabi/9.3.0/lto-wrapper -plugin-opt=3D-fre= solution=3D/tmp/ccXjRFlS.res -X -o build/cubemx.elf -L/usr/local/crossgcc/a= rm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/thumb/v7e-m+fp/hard -L/usr/= local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../..= /arm-none-eabi/lib/thumb/v7e-m+fp/hard -L/usr/local/crossgcc/arm-none-eabi/= bin/../lib/gcc/arm-none-eabi/9.3.0 -L/usr/local/crossgcc/arm-none-eabi/bin/= ../lib/gcc -L/usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi= /9.3.0/../../../../arm-none-eabi/lib lots.o of.o object.o files.o -lm -lnos= ys -Map=3Dbuild/cubemx.map --cref --gc-sections --exclude-libs libc.a -T cu= bemx/STM32F429BITx_FLASH.ld > /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../= ../../../arm-none-eabi/bin/ld: /usr/local/crossgcc/arm-none-eabi/bin/../lib= /gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/= libc.a(lib_a-sbrkr.o): in function `_sbrk_r': > /var/tmp/builds/crossgcc/src/newlib-3.1.0/newlib/libc/reent/sbrkr.c:51: = undefined reference to `_sbrk' > /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../= ../../../arm-none-eabi/bin/ld: /usr/local/crossgcc/arm-none-eabi/bin/../lib= /gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/= libc.a(lib_a-writer.o): in function `_write_r': > /var/tmp/builds/crossgcc/src/newlib-3.1.0/newlib/libc/reent/writer.c:49:= undefined reference to `_write' > /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../= ../../../arm-none-eabi/bin/ld: /usr/local/crossgcc/arm-none-eabi/bin/../lib= /gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/= libc.a(lib_a-closer.o): in function `_close_r': > /var/tmp/builds/crossgcc/src/newlib-3.1.0/newlib/libc/reent/closer.c:47:= undefined reference to `_close' > /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../= ../../../arm-none-eabi/bin/ld: /usr/local/crossgcc/arm-none-eabi/bin/../lib= /gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/= libc.a(lib_a-lseekr.o): in function `_lseek_r': > /var/tmp/builds/crossgcc/src/newlib-3.1.0/newlib/libc/reent/lseekr.c:49:= undefined reference to `_lseek' > /usr/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../= ../../../arm-none-eabi/bin/ld: /usr/local/crossgcc/arm-none-eabi/bin/../lib= /gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/= libc.a(lib_a-readr.o): in function `_read_r': > /var/tmp/builds/crossgcc/src/newlib-3.1.0/newlib/libc/reent/readr.c:49: = undefined reference to `_read' > collect2: error: ld returned 1 exit status > make[1]: *** [cubemx/Makefile:209: build/cubemx.elf] Error 1 > make[1]: Leaving directory '/m/s/rep/git/siemens/it1010/src' > make: *** [Makefile:16: all] Error 2 =2D-=20 Arsen Arsenovi=C4=87 --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iOYEARYKAI4WIQT+4rPRE/wAoxYtYGFSwpQwHqLEkwUCZAccX18UgAAAAAAuAChp c3N1ZXItZnByQG5vdGF0aW9ucy5vcGVucGdwLmZpZnRoaG9yc2VtYW4ubmV0RkVF MkIzRDExM0ZDMDBBMzE2MkQ2MDYxNTJDMjk0MzAxRUEyQzQ5MxAcYXJzZW5AYWFy c2VuLm1lAAoJEFLClDAeosSTFBsA/0w/Kk86pUdrDqFZCnYQLLWNszau7xM/XrFl rarlUCa8AQDWK7h++WpZbnqYUjCdwq6NZx/0q3Cu1tapN0XYYAXwBQ== =k4OI -----END PGP SIGNATURE----- --=-=-=--