Re: [RFC PATCH v2 3/8] tools/nolibc: i386: Implement syscall with 6 arguments

Willy Tarreau
2022-03-22T14:03:07Z

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 <w@1wt.eu>
> > 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 <w@1wt.eu>
> >     Signed-off-by: Paul E. McKenney <paulmck@kernel.org>
> >
> > 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