Bug 29938 - glibc-2.36 fails to build with Os with undefined reference to strcpy
Summary: glibc-2.36 fails to build with Os with undefined reference to strcpy
Status: RESOLVED DUPLICATE of bug 29576
Alias: None
Product: glibc
Classification: Unclassified
Component: build (show other bugs)
Version: 2.36
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-23 12:52 UTC by john.frankish
Modified: 2023-01-03 16:28 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description john.frankish 2022-12-23 12:52:31 UTC
glibc-2.36 fails to build with Os, but builds without error with O2.

Built using:

echo "rootsbindir=/usr/sbin" > configparms

CC="gcc -mtune=generic -Os -pipe" ../configure --prefix=/usr --disable-werror --enable-kernel=5.4.3 --enable-stack-protector=strong --with-headers=/usr/include libc_cv_slibdir=/lib --enable-obsolete-rpc --libexecdir=/usr/lib/glibc

find . -name config.make -type f -exec sed -i 's/-g -O2//g' {} \;
find . -name config.status -type f -exec sed -i 's/-g -O2//g' {} \;
find ../ -name Makeconfig -type f -exec sed -i 's/-g -O2//g' {} \;

make

/usr/lib/gcc/x86_64-tc-linux-gnu/12.2.0/../../../../x86_64-tc-linux-gnu/bin/ld: /sources/glibc-2.36/build/elf/librtld.os: in function `_dl_start_profile':
(.text+0x9587): undefined reference to `strcpy'
/usr/lib/gcc/x86_64-tc-linux-gnu/12.2.0/../../../../x86_64-tc-linux-gnu/bin/ld: /sources/glibc-2.36/build/elf/librtld.os: in function `_dl_load_cache_lookup':
(.text+0xe5fd): undefined reference to `strcpy'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:1346: /sources/glibc-2.36/build/elf/ld.so] Error 1
Comment 1 Noah Goldstein 2022-12-24 01:09:41 UTC
This is a duplicate of: https://sourceware.org/bugzilla/show_bug.cgi?id=29576

and was fixed by:

commit 9dc4e29f630c6ef8299120b275e503321dc0c8c7
Author: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
Date:   Wed Sep 21 10:51:08 2022 -0300

    x86: Fix -Os build (BZ #29576)


Maybe we should backport the fix?
Comment 2 john.frankish 2022-12-25 09:26:44 UTC
If I understand correctly, backporting the commit https://sourceware.org/git/?p=glibc.git;a=commitdiff;h=9dc4e29f630c6ef8299120b275e503321dc0c8c7 means deleting sysdeps/x86_64/multiarch/rtld-strcpy.S

..but the error remains the same with or without this file.
Comment 3 Noah Goldstein 2022-12-26 20:23:20 UTC
(In reply to john.frankish from comment #2)
> If I understand correctly, backporting the commit
> https://sourceware.org/git/?p=glibc.git;a=commitdiff;
> h=9dc4e29f630c6ef8299120b275e503321dc0c8c7 means deleting
> sysdeps/x86_64/multiarch/rtld-strcpy.S
> 
> ..but the error remains the same with or without this file.

Do you have the following commit:

commit 302bc33bc53c787da6e74162a7092e9c0fb964a8
Author: Noah Goldstein <goldstein.w.n@gmail.com>
Date:   Mon Aug 8 11:26:22 2022 +0800

    elf: Replace `strcpy` call with `memcpy` [BZ #29454]
Comment 4 john.frankish 2022-12-27 14:17:37 UTC
Thanks - that appears to have solved the problem of compiling for i486 with -Os.

Note that the glibc-2.36 tarball already contains the file added by commit 9dc4e29f630c6ef8299120b275e503321dc0c8c7

I'll check building for x86_64 with -Os in a day or two.
Comment 5 john.frankish 2022-12-27 14:18:14 UTC
Thanks - that appears to have solved the problem of compiling for i486 with -Os.

Note that the glibc-2.36 tarball already contains the file added by commit 9dc4e29f630c6ef8299120b275e503321dc0c8c7

I'll check building for x86_64 with -Os in a day or two.
Comment 6 Adhemerval Zanella 2022-12-29 12:59:23 UTC
I back(In reply to john.frankish from comment #5)
> Thanks - that appears to have solved the problem of compiling for i486 with
> -Os.
> 
> Note that the glibc-2.36 tarball already contains the file added by commit
> 9dc4e29f630c6ef8299120b275e503321dc0c8c7
> 
> I'll check building for x86_64 with -Os in a day or two.

I just backported the required patch to build glibc with -Os for x86 on 2.36 and I also send some fixes for upstream to build for -Os/-O1 on all targets [1].

[1] https://patchwork.sourceware.org/project/glibc/list/?series=15572
Comment 7 Adhemerval Zanella 2022-12-29 13:00:26 UTC
Mark as duplicated.

*** This bug has been marked as a duplicate of bug 29576 ***
Comment 8 john.frankish 2022-12-31 11:35:57 UTC
glibc-2.36 fails to build with -Os for x86_64 with commit 302bc33bc53c787da6e74162a7092e9c0fb964a8

glibc-2.36 builds with -O2 for x86_64 and it builds with -Os for x86 (i486)

gcc -mtune=generic -Os -pipe   -nostdlib -nostartfiles -shared -o /usr/src/glibc-2.36/build/elf/ld.so.new               \
          -Wl,-z,relro -Wl,-z,defs      \
          -Wl,-z,pack-relative-relocs \
          /usr/src/glibc-2.36/build/elf/librtld.os -Wl,--version-script=/usr/src/glibc-2.36/build/ld.map                \
          -Wl,-soname=ld-linux-x86-64.so.2
/usr/local/bin/ld: /usr/src/glibc-2.36/build/elf/librtld.os: in function `_dl_start_profile':
(.text+0x9643): undefined reference to `strcpy'
collect2: error: ld returned 1 exit status
Comment 9 Adhemerval Zanella 2022-12-31 13:32:29 UTC
(In reply to john.frankish from comment #8)
> glibc-2.36 fails to build with -Os for x86_64 with commit
> 302bc33bc53c787da6e74162a7092e9c0fb964a8
> 
> glibc-2.36 builds with -O2 for x86_64 and it builds with -Os for x86 (i486)
> 
> gcc -mtune=generic -Os -pipe   -nostdlib -nostartfiles -shared -o
> /usr/src/glibc-2.36/build/elf/ld.so.new               \
>           -Wl,-z,relro -Wl,-z,defs      \
>           -Wl,-z,pack-relative-relocs \
>           /usr/src/glibc-2.36/build/elf/librtld.os
> -Wl,--version-script=/usr/src/glibc-2.36/build/ld.map                \
>           -Wl,-soname=ld-linux-x86-64.so.2
> /usr/local/bin/ld: /usr/src/glibc-2.36/build/elf/librtld.os: in function
> `_dl_start_profile':
> (.text+0x9643): undefined reference to `strcpy'
> collect2: error: ld returned 1 exit status

Does it still happen with 2.36 branch [1]?

[1] https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/release/2.36/master
Comment 10 john.frankish 2022-12-31 15:50:39 UTC
If you're referring to commit 4f4d7a13edfd2fdc57c9d76e1fd6d017fb47550c this patch is already present in glibc-2.36.tar.xz

If you're referring to the entire branch [1], please excuse my ignorance, but how do I clone branch [1] from glibc git?
Comment 11 Adhemerval Zanella 2023-01-03 15:13:55 UTC
(In reply to john.frankish from comment #10)
> If you're referring to commit 4f4d7a13edfd2fdc57c9d76e1fd6d017fb47550c this
> patch is already present in glibc-2.36.tar.xz
> 
> If you're referring to the entire branch [1], please excuse my ignorance,
> but how do I clone branch [1] from glibc git?

I mean the git branch for 2.36, since glibc usually does not release minor versions for the source packages release. And the process is described in the 'get started' pane [1]:

$ git clone https://sourceware.org/git/glibc.git
$ cd glibc
$ git checkout release/2.36/master

You can also accomplish the same with one command:

$ git clone -b release/2.36/master https://sourceware.org/git/glibc.git

[1] https://www.gnu.org/software/libc/started.html
Comment 12 john.frankish 2023-01-03 16:28:26 UTC
Thanks - I confirm that both x86 (i486) and x86_64 build with -Os