From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.0 required=5.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 Received: from 1wt.eu (wtarreau.pck.nerim.net [62.212.114.60]) by gnuweeb.org (Postfix) with ESMTP id AAFA17E2DF for ; Tue, 22 Mar 2022 14:03:10 +0000 (UTC) Received: (from willy@localhost) by pcw.home.local (8.15.2/8.15.2/Submit) id 22ME2smt011112; Tue, 22 Mar 2022 15:02:54 +0100 Date: Tue, 22 Mar 2022 15:02:53 +0100 From: Willy Tarreau To: Ammar Faizi Cc: David Laight , "Paul E. McKenney" , Alviro Iskandar Setiawan , Nugraha , Linux Kernel Mailing List , GNU/Weeb Mailing List , "x86@kernel.org" , "llvm@lists.linux.dev" Subject: Re: [RFC PATCH v2 3/8] tools/nolibc: i386: Implement syscall with 6 arguments Message-ID: <20220322140253.GJ10306@1wt.eu> References: <20220322121338.GD10306@1wt.eu> <81569a1c-a6d3-ceb2-a1f1-f229a024d684@gnuweeb.org> <20220322133413.GG10306@1wt.eu> <58cb5455-d065-b508-b328-20b57c3a67a7@gnuweeb.org> <3b8984ecfbcd4c93aeb468d01728cd74@AcuMS.aculab.com> <20220322134100.GH10306@1wt.eu> <9cfcb296-9dfe-aef1-4209-20a3a95c50ba@gnuweeb.org> <98304cd4-a443-5e5e-9764-654ecd1d458b@gnuweeb.org> <8f11bc01-4b63-eaf7-6da3-77556cfb0118@gnuweeb.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <8f11bc01-4b63-eaf7-6da3-77556cfb0118@gnuweeb.org> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: On Tue, Mar 22, 2022 at 08:56:44PM +0700, Ammar Faizi wrote: > On 3/22/22 8:54 PM, Ammar Faizi wrote: > > > > Willy, something goes wrong here... > > > > ammarfaizi2@integral2:~/work/linux.work/tools/include/nolibc$ taskset -c 0 gcc -ffreestanding -nostdlib -nostartfiles test.c -o test -lgcc > > /usr/bin/ld: /tmp/ccHiYiks.o: warning: relocation against `environ' in read-only section `.text' > > /usr/bin/ld: /tmp/ccHiYiks.o: in function `getenv': > > test.c:(.text+0x1f76): undefined reference to `environ' > > /usr/bin/ld: test.c:(.text+0x1fc3): undefined reference to `environ' > > /usr/bin/ld: test.c:(.text+0x1ffc): undefined reference to `environ' > > /usr/bin/ld: test.c:(.text+0x2021): undefined reference to `environ' > > /usr/bin/ld: test.c:(.text+0x2049): undefined reference to `environ' > > /usr/bin/ld: warning: creating DT_TEXTREL in a PIE > > collect2: error: ld returned 1 exit status > > ammarfaizi2@integral2:~/work/linux.work/tools/include/nolibc$ > > > > > > I suspect it's caused by commit: > > > > commit c970abe796019b3d576fd154a54b94efb35c02b1 > > Author: Willy Tarreau > > Date:   Mon Mar 21 18:33:08 2022 +0100 > > > >     tools/nolibc/stdlib: add a simple getenv() implementation > >     This implementation relies on an extern definition of the environ > >     variable, that the caller must declare and initialize from envp. > >     Signed-off-by: Willy Tarreau > >     Signed-off-by: Paul E. McKenney > > > > I will take a look deeper on this... > > This bug only exists when compiling without optimization. Indeed, reproduced. I can bypass it by adding __attribute__((weak)) on the environ declaration in getenv(). Will send a patch later. Thanks, Willy