bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug ld/26815] New: Unnecessary error on linking STV_PROTECTED library:


From: thiago at kde dot org
Subject: [Bug ld/26815] New: Unnecessary error on linking STV_PROTECTED library: relocation R_X86_64_PC32 against protected symbol `f' can not be used when making a shared object
Date: Thu, 29 Oct 2020 20:28:32 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=26815

            Bug ID: 26815
           Summary: Unnecessary error on linking STV_PROTECTED library:
                    relocation R_X86_64_PC32 against protected symbol `f'
                    can not be used when making a shared object
           Product: binutils
           Version: 2.35.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ld
          Assignee: unassigned at sourceware dot org
          Reporter: thiago at kde dot org
  Target Milestone: ---

Using ld.bfd:

$ cat test.c
void f() {} 
void *g() { return &f; }
$ gcc -fPIC -o /tmp/a.so -shared -fvisibility=protected test.c
/usr/bin/ld: /tmp/ccbS1isF.o: relocation R_X86_64_PC32 against protected symbol
`f' can not be used when making a shared object
/usr/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
$ ld --version
GNU ld (GNU Binutils) 2.35.1.20190203
Copyright (C) 2020 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

But it works with gold:
$ gcc -fuse-ld=gold -fPIC -o /tmp/a.so -shared -fvisibility=protected test.c
[no error]

It similarly works with ld.bfd if you pass a dummy dynamic list:

$ cat /tmp/empty.dynlist 
{
    this_symbol_doesnt_exist;
};
$ gcc -Wl,--dynamic-list,/tmp/empty.dynlist -fPIC -o /tmp/a.so -shared
-fvisibility=protected test.c
[no error]

The library looks fine otherwise (using -nostdlib for output brevity):
$ gcc -nostdlib -Wl,--dynamic-list,/tmp/empty.dynlist -fPIC -o /tmp/a.so
-shared -fvisibility=protected test.c
$ readelf -Ds /tmp/a.so

Symbol table for image contains 3 entries:
   Num:    Value          Size Type    Bind   Vis      Ndx Name
     0: 0000000000000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 0000000000001001     8 FUNC    GLOBAL PROTECTED    6 g
     2: 0000000000001000     1 FUNC    GLOBAL PROTECTED    6 f
$ readelf -r /tmp/a.so

There are no relocations in this file.
$ objdump -d /tmp/a.so

/tmp/a.so:     file format elf64-x86-64

Disassembly of section .text:

0000000000001000 <f>:
    1000:       c3                      retq   

0000000000001001 <g>:
    1001:       48 8d 05 f8 ff ff ff    lea    -0x8(%rip),%rax        # 1000
<f>
    1008:       c3                      retq

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]