Message ID | 20220824180426.820576-1-keithp@keithp.com |
---|---|
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1544465wro; Wed, 24 Aug 2022 11:12:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR4f0t97g2IaRxXDPre9HsGSYiZc6jE2tx5esjOu3K9CkfRT0Bs2i/44Cp85rOADuhTpsu1z X-Received: by 2002:a17:907:87b0:b0:731:36ab:3223 with SMTP id qv48-20020a17090787b000b0073136ab3223mr93671ejc.715.1661364747043; Wed, 24 Aug 2022 11:12:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661364747; cv=none; d=google.com; s=arc-20160816; b=P88hsQ9k5ahPGFdSXlU9B8TUajFpARKH1W9XT4yWw1XJmdAniwFT7RjxZ8m8TN6erx Xs28wokUtba0qdFcFl9RyKwxijbADTuB2kRDSUUcLL71GsHrfYONQcSSNNbGrmB6iYEf MwvTv8dwm1sJcCapw2dC6zbNOuIwU5ZdhQgCSURg1XUQzVmgH84wMJNPSzy8+H4smn0a 41zqFr34RudyxccBmdAShwpO+FCXlq1UFGbkrbc516zQqGJ3FrBt2AYMqYNKLbIN4CdA +Kyu3rt9dadUjKF6X5KHgSnS9YSlNhBYNqrOggA/LmVhXRC/Bd8EB0EH2qdgL0enr2AR 3jKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=sN/KCA0G5RPexeO2U1QspdZEofiD0Z6MwQSzJzGSsRs=; b=TNXy238e9SqNW2Jr7e/KQzbwdQszYS5jT/7KaX5pI/+TNgEjqs7HNZVfgkawPr8eHV GkOGLDJLecUqYVaKQaMiCf3A+lFOlkbwy758XIHkJDkbrFYpjOT/MgS8I9QuC+SSPJA/ z0NHwhIk675aROMuqrwloULsSBVY4m8ktKC0Lece1rcI0d6UjjWTU3vW1tZwwuYPd3WZ TcWP0oHJ3WbwTtYRikz2ayqwaz6ZUfCXA+eQEswQjjc91DUuFAGsxoFEQvNRsw7HKGYi AdDnnz0jfI2IeyYY8f1KSJc7AEf3Q6wWpfVl7kpxn/70tkMXdHEEIY7lO8BLDMrl9iJL lADA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hp+mw3Ux; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id gb18-20020a170907961200b0072f0f088ed7si2389594ejc.712.2022.08.24.11.12.26 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Aug 2022 11:12:27 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=hp+mw3Ux; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9A8E4388DD23 for <ouuuleilei@gmail.com>; Wed, 24 Aug 2022 18:08:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9A8E4388DD23 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661364538; bh=sN/KCA0G5RPexeO2U1QspdZEofiD0Z6MwQSzJzGSsRs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=hp+mw3UxRXYo8WgSgZjfqYI0XBG1EKe/Tfe9b02bPqpinOwadcI13fuV9uMHaPj9j RudIrHuzojp4XRSg0QSV9xX4k7kUamOVKOFhiKlVqlvRyhurnILiqDv9UXP+A70AU1 IYunCAXdHtearaxVaMwnIkuShsRW1kAzIRVGAf9g= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from elaine.keithp.com (home.keithp.com [63.227.221.253]) by sourceware.org (Postfix) with ESMTPS id 9D3D53838004; Wed, 24 Aug 2022 18:05:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 9D3D53838004 Received: from localhost (localhost [127.0.0.1]) by elaine.keithp.com (Postfix) with ESMTP id 9625C3F2FE55; Wed, 24 Aug 2022 11:05:31 -0700 (PDT) X-Virus-Scanned: Debian amavisd-new at keithp.com Received: from elaine.keithp.com ([127.0.0.1]) by localhost (elaine.keithp.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 1sZb9GBPRgyz; Wed, 24 Aug 2022 11:05:26 -0700 (PDT) Received: from keithp.com (koto.keithp.com [192.168.11.2]) by elaine.keithp.com (Postfix) with ESMTPSA id 74E673F2FE8B; Wed, 24 Aug 2022 11:05:26 -0700 (PDT) Received: by keithp.com (Postfix, from userid 1000) id 0C67D1E601CB; Wed, 24 Aug 2022 11:05:26 -0700 (PDT) To: gcc@gcc.gnu.org Subject: [PATCH 0/3] picolibc: Add picolibc linking help Date: Wed, 24 Aug 2022 11:04:23 -0700 Message-Id: <20220824180426.820576-1-keithp@keithp.com> X-Mailer: git-send-email 2.36.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> From: Keith Packard via Gcc-patches <gcc-patches@gcc.gnu.org> Reply-To: Keith Packard <keithp@keithp.com> Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1742067200835756997?= X-GMAIL-MSGID: =?utf-8?q?1742067200835756997?= |
Series |
picolibc: Add picolibc linking help
|
|
Message
Keith Packard
Aug. 24, 2022, 6:04 p.m. UTC
Picolibc is a C library for embedded systems based on code from newlib and avr libc. To connect some system-dependent picolibc functions (like stdio) to an underlying platform, the platform may provide an OS library. This OS library must follow the C library in the link command line. In current picolibc, that is done by providing an alternate .specs file which can rewrite the *lib spec to insert the OS library in the right spot. This patch series adds the ability to specify the OS library on the gcc command line when GCC is configured to us picolibc as the default C library, and then hooks that up for arm, nds32, riscv and sh targets. Keith Packard (3): Allow default libc to be specified to configure Add newlib and picolibc as default C library choices Add '--oslib=' option when default C library is picolibc gcc/config.gcc | 56 ++++++++++++++++++++++++++++++++------- gcc/config/arm/elf.h | 5 ++++ gcc/config/nds32/elf.h | 4 +++ gcc/config/picolibc.opt | 26 ++++++++++++++++++ gcc/config/riscv/elf.h | 4 +++ gcc/config/sh/embed-elf.h | 5 ++++ gcc/configure.ac | 4 +++ 7 files changed, 95 insertions(+), 9 deletions(-) create mode 100644 gcc/config/picolibc.opt
Comments
On Wed, Aug 24, 2022 at 11:12 AM Keith Packard via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Picolibc is a C library for embedded systems based on code from newlib > and avr libc. To connect some system-dependent picolibc functions > (like stdio) to an underlying platform, the platform may provide an OS > library. > > This OS library must follow the C library in the link command line. In > current picolibc, that is done by providing an alternate .specs file > which can rewrite the *lib spec to insert the OS library in the right > spot. Why do you need to change the specs to support picolibc? Why not have the library supply the specs file instead, like what is done for newlib and libgloss? > > This patch series adds the ability to specify the OS library on the > gcc command line when GCC is configured to us picolibc as the default > C library, and then hooks that up for arm, nds32, riscv and sh targets. What OS libraries are not included in libc? I trying to figure out why this needs to be special cased here. Thanks, Andrew Pinski > > Keith Packard (3): > Allow default libc to be specified to configure > Add newlib and picolibc as default C library choices > Add '--oslib=' option when default C library is picolibc > > gcc/config.gcc | 56 ++++++++++++++++++++++++++++++++------- > gcc/config/arm/elf.h | 5 ++++ > gcc/config/nds32/elf.h | 4 +++ > gcc/config/picolibc.opt | 26 ++++++++++++++++++ > gcc/config/riscv/elf.h | 4 +++ > gcc/config/sh/embed-elf.h | 5 ++++ > gcc/configure.ac | 4 +++ > 7 files changed, 95 insertions(+), 9 deletions(-) > create mode 100644 gcc/config/picolibc.opt > > -- > 2.36.1 >
Andrew Pinski <pinskia@gmail.com> writes: (removing gcc@ as not appropriate for patch discussions) Thanks for reviewing my patches; I appreciate the time you have taken to think about this. > Why do you need to change the specs to support picolibc? Why not have > the library supply the specs file instead, like what is done for > newlib and libgloss? Several architectures do include support for newlib's libgloss in their gcc configuration today (i386, m32r, microblaze, nds32, pru, riscv and sh), so I wondered if it made sense to add support for picolibc's target-specific libraries as well. Picolibc does deliver a spec file fragment which implements this functionality, but that requires the addition of --specs=picolibc.specs to the gcc command line instead of being built-in to gcc itself. When creating an integrated toolchain using picolibc, it seems a bit odd to require an option for the toolchain to work. > What OS libraries are not included in libc? I trying to figure out why > this needs to be special cased here. As a general-purpose embedded C library, picolibc doesn't include any OS-specific code. Instead, it defines a limited subset of POSIX interfaces which are to be supplied by the target platform. Picolibc itself supplies sample implementations of these ABIs that can run on top of bare metal systems with semihosting support which are used while testing picolibc itself. This is similar to newlib's libgloss: the C library is built atop another library which needs to follow it in the linker command line for symbol resolution to work correctly. Making this work requires a change in the *lib spec file fragment. Adjusting the *lib fragment can either be done in an externally provided specs file, or built-in to gcc. Both of these mechanisms are present in the gcc ecosystem today, leading me to wonder whether the gcc community would be interested in having an integrated option available.
I am thinking that maybe we should add -mlibc=[newlib|newlib-nano|picolibc|unknown] option to bare-matel toolchain, one reason is having an unify interface to select libc implementation between clang/LLVM, spec file is a GCC specific stuff, that cause very bad compatibility between GCC and clang/LLVM, and having option to control that would be better since clang/LLVM don't have those configure time option. For linux toolchain, it uses -mbionic, -muclibc, -mglibc and -mmusl, maybe we could also use an unify -mlibc= option for that? On Thu, Aug 25, 2022 at 3:32 AM Keith Packard via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Andrew Pinski <pinskia@gmail.com> writes: > > (removing gcc@ as not appropriate for patch discussions) > > Thanks for reviewing my patches; I appreciate the time you have taken to > think about this. > > > Why do you need to change the specs to support picolibc? Why not have > > the library supply the specs file instead, like what is done for > > newlib and libgloss? > > Several architectures do include support for newlib's libgloss in their > gcc configuration today (i386, m32r, microblaze, nds32, pru, riscv and > sh), so I wondered if it made sense to add support for picolibc's > target-specific libraries as well. > > Picolibc does deliver a spec file fragment which implements this > functionality, but that requires the addition of --specs=picolibc.specs > to the gcc command line instead of being built-in to gcc itself. When > creating an integrated toolchain using picolibc, it seems a bit odd to > require an option for the toolchain to work. > > > What OS libraries are not included in libc? I trying to figure out why > > this needs to be special cased here. > > As a general-purpose embedded C library, picolibc doesn't include any > OS-specific code. Instead, it defines a limited subset of POSIX > interfaces which are to be supplied by the target platform. > > Picolibc itself supplies sample implementations of these ABIs that can > run on top of bare metal systems with semihosting support which are used > while testing picolibc itself. > > This is similar to newlib's libgloss: the C library is built atop > another library which needs to follow it in the linker command line for > symbol resolution to work correctly. Making this work requires a change > in the *lib spec file fragment. > > Adjusting the *lib fragment can either be done in an externally provided > specs file, or built-in to gcc. Both of these mechanisms are present in > the gcc ecosystem today, leading me to wonder whether the gcc community > would be interested in having an integrated option available. > > -- > -keith
Kito Cheng <kito.cheng@gmail.com> writes: > I am thinking that maybe we should add > -mlibc=[newlib|newlib-nano|picolibc|unknown] option to bare-matel > toolchain, one reason is having an unify interface to select libc > implementation between clang/LLVM, spec file is a GCC specific stuff, > that cause very bad compatibility between GCC and clang/LLVM, and > having option to control that would be better since clang/LLVM don't > have those configure time option. You can create specs file for each library so that you select the library with --specs=picolibc.specs or --specs=newlib-nano.specs. That seems sufficient as you can mess with various compiler options and set the header paths. Crosstool-ng does this and it enables delivering newlib, newlib-nano and picolibc in the same toolchain.
Keith Packard via Gcc-patches <gcc-patches@gcc.gnu.org> writes: > Picolibc is a C library for embedded systems based on code from newlib > and avr libc. To connect some system-dependent picolibc functions > (like stdio) to an underlying platform, the platform may provide an OS > library. > > This OS library must follow the C library in the link command line. In > current picolibc, that is done by providing an alternate .specs file > which can rewrite the *lib spec to insert the OS library in the right > spot. > > This patch series adds the ability to specify the OS library on the > gcc command line when GCC is configured to us picolibc as the default > C library, and then hooks that up for arm, nds32, riscv and sh targets. Not really my area, but the approach LGTM FWIW. Main question/points: - In: +case "${with_default_libc}" in +glibc) + default_libc=LIBC_GLIBC + ;; should there be a default case that raises an error for unrecognised libcs? Command-line checking for configure isn't very tight, but we do raise similar errors for things like invalid --enable-threads values. - I'm not sure either way about adding LIBC_NEWLIB. On the one hand it makes sense for completeness, but on the other it's write-only. Adding it means that --with-default-libc=newlib toolchains have a different macro configuration from a default toolchain even in cases where newlib is the default. On balance I think it would be better to accept --with-default-libc=newlib but set default_libc to the empty string. - Should we raise an error for toolchains that don't support the given C library? It feels like we should, but I realise that could be difficult to do. - Very minor, but in lines like: +#if defined(DEFAULT_LIBC) && defined(LIBC_PICOLIBC) && DEFAULT_LIBC == LIBC_PICOLIBC is LIBC_PICOLIB ever undefined? It looks like config.gcc provides an unconditional definition. If it is always defined then: #if DEFAULT_LIBC == LIBC_PICOLIB would be clearer. Thanks, Richard > > Keith Packard (3): > Allow default libc to be specified to configure > Add newlib and picolibc as default C library choices > Add '--oslib=' option when default C library is picolibc > > gcc/config.gcc | 56 ++++++++++++++++++++++++++++++++------- > gcc/config/arm/elf.h | 5 ++++ > gcc/config/nds32/elf.h | 4 +++ > gcc/config/picolibc.opt | 26 ++++++++++++++++++ > gcc/config/riscv/elf.h | 4 +++ > gcc/config/sh/embed-elf.h | 5 ++++ > gcc/configure.ac | 4 +++ > 7 files changed, 95 insertions(+), 9 deletions(-) > create mode 100644 gcc/config/picolibc.opt
Richard Sandiford <richard.sandiford@arm.com> writes: Thanks much for reviewing this series. I really appreciate it. > should there be a default case that raises an error for unrecognised > libcs? Command-line checking for configure isn't very tight, but we > do raise similar errors for things like invalid --enable-threads > values. Good thinking. It's way to easy to introduce a typo somewhere and have it get missed. > On balance I think it would be better to accept > --with-default-libc=newlib but set default_libc to the empty string. That also makes good sense -- leave existing configurations unchanged. > - Should we raise an error for toolchains that don't support the given > C library? It feels like we should, but I realise that could be > difficult to do. That would be nice, but it also feels like making it reliable enough to be useful would be difficult to maintain in the future, even if we did manage to make it mostly work today. > - Very minor, but in lines like: > > +#if defined(DEFAULT_LIBC) && defined(LIBC_PICOLIBC) && DEFAULT_LIBC == LIBC_PICOLIBC > > is LIBC_PICOLIB ever undefined? It looks like config.gcc provides > an unconditional definition. If it is always defined then: > > #if DEFAULT_LIBC == LIBC_PICOLIB > > would be clearer. Agreed. Thanks again for taking a look; I'll send a new series with these issues fixed shortly.
Picolibc is a C library for embedded systems based on code from newlib and avr libc. To connect some system-dependent picolibc functions (like stdio) to an underlying platform, the platform may provide an OS library. This OS library must follow the C library in the link command line. In current picolibc, that is done by providing an alternate .specs file which can rewrite the *lib spec to insert the OS library in the right spot. This patch series adds the ability to specify the OS library on the gcc command line when GCC is configured to us picolibc as the default C library, and then hooks that up for arm, nds32, riscv and sh targets. This is the second version of these patches which address several issues raised in review by Richard Sandiford. Keith Packard (3): Allow default libc to be specified to configure Add newlib and picolibc as default C library choices Add '--oslib=' option when default C library is picolibc gcc/config.gcc | 65 +++++++++++++++++++++++++++++++++------ gcc/config/arm/elf.h | 5 +++ gcc/config/nds32/elf.h | 4 +++ gcc/config/picolibc.opt | 26 ++++++++++++++++ gcc/config/riscv/elf.h | 4 +++ gcc/config/sh/embed-elf.h | 5 +++ gcc/configure.ac | 4 +++ 7 files changed, 104 insertions(+), 9 deletions(-) create mode 100644 gcc/config/picolibc.opt