From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [IPv6:2a00:1450:4864:20::534]) by sourceware.org (Postfix) with ESMTPS id 7DA983858D33 for ; Wed, 22 Feb 2023 09:02:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7DA983858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-ed1-x534.google.com with SMTP id x10so26598164edd.13 for ; Wed, 22 Feb 2023 01:02:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=sOnCLXAGY4LVCVmzek7bRDjFJwShl34Rbfsc2EUFtds=; b=jLo69ZcAxS/ikvRU3xoOo2qeUks2YZaQgGOESDdGeE/MlreHQB9LUYwHxEdiVo1L8J OcoZzESIlGnkVI1kUmF9RlxNN3C1V4ymzfwcQqXAv9YDboKMKpVXm7MBxQ5R0GooWJLW 7lhufQ4myY4zrAwBKNhR1SL1SA+HRqkg/QqwXzoDQuIrWTruW1xlZZthstzRO+CIrXKb fDR2DL+GNXCGzJVpoTHpTqGWt5nHMsuSfyBxDoz7hcCr53IZwy/e4qjzFBU2k5w/bcP1 5ppmwX1t0aZWJNGwLXmMMmndrrU/JwykDNFMKZkqmFR6s4dFmYn/o4jprCgrFbnwoGSB +jnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=sOnCLXAGY4LVCVmzek7bRDjFJwShl34Rbfsc2EUFtds=; b=u4I123E1490zx+CvA1ugF8j3ricYFXY84ly4XRVdDU6XYLxiG+7WcmoYHz6SnlJSFF gbDXpciV7M0YEqHnrMqzy1K09fCcgdnS2l+EvdO7PZChGZ9WbexbnWrfiUF1+4bErfc3 HS4qCvLoH37e+3I+rh8bSNR/6Eot07DWa3a5RUwV3H00prq0IR0rNKn6lyyeHpkoLUk6 KpuqrAFxgW+mziWD+4+KPhKcoKh320mb9mINxk/eMblmRSQZFApIGDPvLzwytVfmjm1h kgQ+3XiXOd2kibR26uPEuJEII5A9cbtBIap7BOZbRoXDVGcs1F14hBxz0B43P+m7FB98 5tSw== X-Gm-Message-State: AO0yUKXslR9KK4n2w0mgLxOdXN6Pycy3k3r9hyP2MxR2PW73W/3mDsx2 xW51bm3YShPou1Kj2cTQEVlGAADDPdhw+lxaaq0= X-Google-Smtp-Source: AK7set/FYAUQTkPAJdcwc+jdkuYyaNnsZFvIXyGRTo5zcJSahok7ZadhlddbvaIB6juQ3eLNaN4GAv+gsTUnWY5mvtM= X-Received: by 2002:a17:906:13d9:b0:8de:c6a6:5134 with SMTP id g25-20020a17090613d900b008dec6a65134mr2536932ejc.15.1677056555168; Wed, 22 Feb 2023 01:02:35 -0800 (PST) MIME-Version: 1.0 References: <20230221233125.GA2142@raven.inka.de> In-Reply-To: <20230221233125.GA2142@raven.inka.de> From: Jonathan Wakely Date: Wed, 22 Feb 2023 09:02:23 +0000 Message-ID: Subject: Re: How to omit libc (newlib) on bare metal (freestanding)? To: Josef Wolf , gcc-help Content-Type: multipart/alternative; boundary="0000000000003d372405f54628ac" X-Spam-Status: No, score=-0.5 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,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: --0000000000003d372405f54628ac Content-Type: text/plain; charset="UTF-8" On Tue, 21 Feb 2023, 23:32 Josef Wolf, wrote: > Hello all, > > I am trying to build for a bare metal target without any OS support and I > want > to omit libc (newlib). > Do you mean you're trying to build GCC itself, or you're trying to build your own program? > So I add > > -ffunction-sections -nostdlib -ffreestanding > > flags to assembler/compiler and > > -lnosys -nolibc -nodefaultlibs -nostartfiles -nostdlib -ffreestanding > -static-libgcc -lgcc -lnosys -nolibc -nodefaultlibs -nostartfiles > -nostdlib -ffreestanding -static-libgcc -lgcc > > to linker Please show the full commands you're using If you add -v to the gcc command it will show exactly what it's doing. > > > But gcc still tries to pull newlib: > > /m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: > /m/a/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-init.o): > in function `__libc_init_array': > /var/tmp/builds/crossgcc/src/newlib-3.1.0/newlib/libc/misc/init.c:40: > undefined reference to `_init' > /m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: > /m/a/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' > /m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: > /m/a/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' > /m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: > /m/a/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' > /m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: > /m/a/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' > /m/a/local/crossgcc/arm-none-eabi/bin/../lib/gcc/arm-none-eabi/9.3.0/../../../../arm-none-eabi/bin/ld: > /m/a/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 > > So what is the magic option to tell gcc not to mess around with libc > (newlib)? > > Thanks! > > > --0000000000003d372405f54628ac--