https://sourceware.org/bugzilla/show_bug.cgi?id=22750
Bug ID: 22750
Summary: .sizeof. directive is handled incorrectly in shared
object
Product: binutils
Version: 2.31 (HEAD)
Status: NEW
Severity: normal
Priority: P2
Component: ld
Assignee: unassigned at sourceware dot org
Reporter: hjl.tools at gmail dot com
Target Milestone: ---
[hjl@gnu-6 sizeof-3]$ cat pr21964-3a.c
#include <stdint.h>
extern int __start___verbose[];
extern int __stop___verbose[];
extern intptr_t sizeof___verbose __attribute__ ((visibility ("hidden")));
int
foo1 (void)
{
static int my_var[5] __attribute__((used, section("__verbose")))
= { 5, 4, 3, 2, 1 };
if (__start___verbose == __stop___verbose
|| __start___verbose[0] != 5
|| sizeof___verbose != (5 * sizeof (int)))
return -1;
else
return 0;
}
[hjl@gnu-6 sizeof-3]$ cat pr21964-3b.c
#include <stdint.h>
extern int __start___verbose[];
extern int __stop___verbose[];
extern intptr_t sizeof___verbose __attribute__ ((visibility ("hidden")));
int
foo2 (void)
{
static int my_var[10] __attribute__((used, section("__verbose")))
= { 10, 9, 8, 7, 6, 5, 4, 3, 2, 1 };
if (__start___verbose == __stop___verbose
|| __start___verbose[0] != 10
|| sizeof___verbose != (10 * sizeof (int)))
return -1;
else
return 0;
}
[hjl@gnu-6 sizeof-3]$ cat pr21964-3c.c
#include <stdio.h>
#include <stdint.h>
extern int foo1 (void);
extern int foo2 (void);
extern int __start___verbose[];
extern int __stop___verbose[];
static int my_var[6] __attribute__((used, section("__verbose")))
= { 6, 4, 3, 2, 1 };
extern intptr_t sizeof___verbose __attribute__ ((visibility ("hidden")));
int
bar (void)
{
if (__start___verbose == __stop___verbose)
return -1;
if (__start___verbose[0] != 6
|| sizeof___verbose != (6 * sizeof (int)))
return -2;
else
return 0;
}
int
main ()
{
if (bar () == 0
&& foo1 () == 0
&& foo2 () == 0)
printf ("PASS\n");
else
printf ("FAIL\n");
return 0;
}
[hjl@gnu-6 sizeof-3]$ cat pr21964-3d.s
.data
.align 8
.ifdef UNDERSCORE
.globl _sizeof___verbose
.type _sizeof___verbose, %object
_sizeof___verbose:
.dc.a .sizeof. (__verbose)
.size _sizeof___verbose, .-_sizeof___verbose
.else
.globl sizeof___verbose
.type sizeof___verbose, %object
sizeof___verbose:
.dc.a .sizeof. (__verbose)
.size sizeof___verbose, .-sizeof___verbose
.endif
[hjl@gnu-6 sizeof-3]$ make
gcc -B./ -g -c -o pr21964-3c.o pr21964-3c.c
as -o pr21964-3d.o pr21964-3d.s
gcc -B./ -g -fPIC -c -o pr21964-3a.o pr21964-3a.c
./ld -shared -o pr21964-3a.so pr21964-3a.o pr21964-3d.o
gcc -B./ -g -fPIC -c -o pr21964-3b.o pr21964-3b.c
./ld -shared -o pr21964-3b.so pr21964-3b.o pr21964-3d.o
gcc -B./ -o pr21964-3 pr21964-3c.o pr21964-3d.o pr21964-3a.so pr21964-3b.so
-Wl,-R,.
./pr21964-3
FAIL
[hjl@gnu-6 sizeof-3]$
[hjl@gnu-6 sizeof-3]$ gdb ./pr21964-3
GNU gdb (GDB) Fedora 8.0.1-35.0.fc27
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-redhat-linux-gnu".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
Find the GDB manual and other documentation resources online at:
<http://www.gnu.org/software/gdb/documentation/>.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from ./pr21964-3...done.
(gdb) b main
Breakpoint 1 at 0x40068d: file pr21964-3c.c, line 29.
(gdb) r
Starting program: /export/home/hjl/bugs/binutils/sizeof-3/pr21964-3
Missing separate debuginfos, use: dnf debuginfo-install
glibc-2.26-25.0.fc27.x86_64
Breakpoint 1, main () at pr21964-3c.c:29
29 if (bar () == 0
(gdb) list
24 }
25
26 int
27 main ()
28 {
29 if (bar () == 0
30 && foo1 () == 0
31 && foo2 () == 0)
32 printf ("PASS\n");
33 else
(gdb) call bar ()
$1 = 0
(gdb) call foo1 ()
$2 = -1
(gdb) call foo2 ()
$3 = -1
(gdb)
.sizeof. (__verbose) in shared object gets the size of __verbose
in executable.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
bug-binutils mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-binutils