bug-binutils
[Top][All Lists]
Advanced

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

[Bug ld/28875] ld should warn or error out about creating copy relocs &


From: thiago at kde dot org
Subject: [Bug ld/28875] ld should warn or error out about creating copy relocs & direct external references for protected symbols
Date: Thu, 10 Feb 2022 20:06:17 +0000

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

--- Comment #2 from Thiago Macieira <thiago at kde dot org> ---
(In reply to H.J. Lu from comment #1)
> Created attachment 13964 [details]
> A patch
> 
> Try this.

Confirmed for copy relocations:

$ cat main.cpp
extern __attribute__((visibility("default"))) long internal_i;
extern __attribute__((visibility("default"))) long internal_f();

int main()
{
    internal_i = (long) &internal_f;
    return (long) &internal_f;
}
$ gcc main.cpp libb.so
/home/tjmaciei/dev/gcc/lib/gcc/x86_64-pc-linux-gnu/12.0.1/../../../../x86_64-pc-linux-gnu/bin/ld:
/tmp/ccwnIS4o.o: copy relocation against non-copyable protected symbol
`internal_i' in libb.so
collect2: error: ld returned 1 exit status

But not for PLT entries:

$ cat main2.cpp
extern __attribute__((visibility("default"))) long internal_f();

int main()
{
    return (long) &internal_f;
}
$ gcc main2.cpp libb.so
[no error]
$ objdump --no-show -Cdr a.out| sed -n '/<main>:/,/^$/p'
0000000000401126 <main>:
  401126:       push   %rbp
  401127:       mov    %rsp,%rbp
  40112a:       mov    $0x401030,%eax
  40112f:       pop    %rbp
  401130:       ret    

glibc 2.35 does not complain about this binary by default:

$ LD_LIBRARY_PATH=. ./a.out; printf %x\\n $? 
30

Only if the PLT is processed:

$ LD_BIND_NOW=1 LD_LIBRARY_PATH=. ./a.out                 
./a.out: _Z10internal_fv: ./libb.so: non-canonical reference to canonical
protected function

-- 
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]