Bug 29512 - ld non-canon ref to canon protected function check breaks Solaris/x86
Summary: ld non-canon ref to canon protected function check breaks Solaris/x86
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.39
: P2 normal
Target Milestone: 2.40
Assignee: H.J. Lu
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2022-08-22 12:30 UTC by Rainer Orth
Modified: 2023-01-23 16:22 UTC (History)
2 users (show)

See Also:
Host: i?86-pc-solaris2.11
Target: i?86-pc-solaris2.11
Build: i?86-pc-solaris2.11
Last reconfirmed:


Attachments
A patch (1015 bytes, patch)
2022-08-22 17:42 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Rainer Orth 2022-08-22 12:30:08 UTC
While I'd successfully bootstrapped gcc trunk with binutils from the 2.39 branch
on Solaris 11.4/x86 some time ago,trying the same with the actual release broke:

genmatch fails to link with

/vol/gcc/bin/gld-2.39: ../libcpp/libcpp.a(macro.o): non-canonical reference to canonical protected function `gmtime@@SYSVABI_1.3' in /lib/libc.so
/vol/gcc/bin/gld-2.39: failed to set dynamic section sizes: bad value
collect2: error: ld returned 1 exit status
make[3]: *** [Makefile:3040: build/genmatch] Error 1

From the description of the patch introducing this (late in the 2.39 release
cycle), I get the impression that this imposes a glibc requirement on all x86 ELF
targets.

By disabling the check in bfd/elf32-i386.c and bfd/elf64-x86-64.c, I managed to
finish the bootstrap successfully.
Comment 1 H.J. Lu 2022-08-22 17:18:46 UTC
The code in question is

              struct tm *tb = (kind == CPP_time_kind::FIXED
                               ? gmtime : localtime) (&tt);

There is no pointer comparison here.  We can ignore protected visibility in
shared libraries on Solaris.
Comment 2 H.J. Lu 2022-08-22 17:42:10 UTC
Created attachment 14288 [details]
A patch

Try this.
Comment 3 Rainer Orth 2022-08-23 14:04:18 UTC
> --- Comment #2 from H.J. Lu <hjl.tools at gmail dot com> ---
> Created attachment 14288 [details]
>   --> https://sourceware.org/bugzilla/attachment.cgi?id=14288&action=edit
> A patch
>
> Try this.

I've just successfully completed a i386-pc-solaris2.11 bootstrap.  Looks
good to go.  Thanks.
Comment 4 Sourceware Commits 2022-08-25 16:12:56 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2c43d202aefb2b6f202a44bbb8a0baf251aae845

commit 2c43d202aefb2b6f202a44bbb8a0baf251aae845
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Mon Aug 22 10:26:17 2022 -0700

    x86: Ignore protected visibility in shared libraries on Solaris
    
    On x86, the PLT entry in executable may be used as function address for
    functions in shared libraries.  If functions are protected, the function
    address used in executable can be different from the function address
    used in shared library.  This will lead to incorrect run-time behavior
    if function pointer equality is needed.  By default, x86 linker issues
    an error in this case.
    
    On Solaris, linker issued an error for
    
    struct tm *tb = (kind == CPP_time_kind::FIXED ? gmtime : localtime) (&tt);
    
    where gmtime is a protected function in libc.so.  Use gmtime's PLT entry
    in executable as function address is safe since function pointer equality
    isn't needed.  Ignore protected visibility in shared libraries on Solaris
    to disable linker error.  If function pointer equality is needed, linker
    will silently generate executable with incorrect run-time behavior on
    Solaris.
    
            PR ld/29512
            * elf32-i386.c (elf_i386_scan_relocs): Ignore protected
            visibility in shared libraries on Solaris.
            * elf64-x86-64.c (elf_x86_64_scan_relocs): Likewise.
Comment 5 H.J. Lu 2023-01-23 16:22:46 UTC
Fixed