Fix spurious glibc version dependency with -z mark-plt on non-Linux

Message ID 20240709005454.zepkvyujchda6f5n@begin
State New
Headers
Series Fix spurious glibc version dependency with -z mark-plt on non-Linux |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_binutils_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 success Build passed
linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_binutils_check--master-arm success Test passed

Commit Message

Samuel Thibault July 9, 2024, 12:54 a.m. UTC
  916730425594 ("elf: Add elf_backend_add_glibc_version_dependency")
introduced adding an extra GLIBC_2.36 version dependency for x86_64. But
on x86_64 GNU/Hurd, there has never been a glibc 2.36 port, and thus the
GLIBC_2.36 version is not defined. The additional version dependency is
thus spurious and produces binaries that cannot be executed:

./test: /lib/x86_64-gnu/libc.so.0.3: version `GLIBC_2.36' not found (required by ./test)

This change fixes this by adding the version dependency only on x86_64
Linux.
  

Comments

H.J. Lu July 9, 2024, 1:01 a.m. UTC | #1
On Tue, Jul 9, 2024, 8:55 AM Samuel Thibault <samuel.thibault@gnu.org>
wrote:

> 916730425594 ("elf: Add elf_backend_add_glibc_version_dependency")
> introduced adding an extra GLIBC_2.36 version dependency for x86_64. But
> on x86_64 GNU/Hurd, there has never been a glibc 2.36 port, and thus the
> GLIBC_2.36 version is not defined. The additional version dependency is
> thus spurious and produces binaries that cannot be executed:
>
> ./test: /lib/x86_64-gnu/libc.so.0.3: version `GLIBC_2.36' not found
> (required by ./test)
>
> This change fixes this by adding the version dependency only on x86_64
> Linux.
>

That is wrong.  Your patch checks the
building system, which can be different
from the target.

H.J.

>
  
H.J. Lu July 9, 2024, 1:37 a.m. UTC | #2
Please open a binutils bug and CC me.


H.J.

On Tue, Jul 9, 2024, 9:01 AM H.J. Lu <hjl.tools@gmail.com> wrote:

>
> On Tue, Jul 9, 2024, 8:55 AM Samuel Thibault <samuel.thibault@gnu.org>
> wrote:
>
>> 916730425594 ("elf: Add elf_backend_add_glibc_version_dependency")
>> introduced adding an extra GLIBC_2.36 version dependency for x86_64. But
>> on x86_64 GNU/Hurd, there has never been a glibc 2.36 port, and thus the
>> GLIBC_2.36 version is not defined. The additional version dependency is
>> thus spurious and produces binaries that cannot be executed:
>>
>> ./test: /lib/x86_64-gnu/libc.so.0.3: version `GLIBC_2.36' not found
>> (required by ./test)
>>
>> This change fixes this by adding the version dependency only on x86_64
>> Linux.
>>
>
> That is wrong.  Your patch checks the
> building system, which can be different
> from the target.
>
> H.J.
>
>>
  
Samuel Thibault July 9, 2024, 7:27 a.m. UTC | #3
H.J. Lu, le mar. 09 juil. 2024 09:01:35 +0800, a ecrit:
> On Tue, Jul 9, 2024, 8:55 AM Samuel Thibault <[1]samuel.thibault@gnu.org>
> wrote:
> 
>     This change fixes this by adding the version dependency only on x86_64
>     Linux.
> 
> 
> That is wrong.  Your patch checks the
> building system, which can be different
> from the target.

Ah, right.

H.J. Lu, le mar. 09 juil. 2024 09:37:59 +0800, a ecrit:
> Please open a binutils bug and CC me.

done so.

Samuel
  

Patch

diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 60aa1802552..8cdb0d3eef7 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -5694,12 +5694,14 @@  elf_x86_64_add_glibc_version_dependency
       i++;
     }
 
+#ifdef __linux__
   htab = elf_x86_hash_table (rinfo->info, X86_64_ELF_DATA);
   if (htab != NULL && htab->params->mark_plt)
     {
       version[i] = "GLIBC_2.36";
       i++;
     }
+#endif
 
   if (i != 0)
     _bfd_elf_link_add_glibc_version_dependency (rinfo, version);