First Last Prev Next    No search results available      Search page      Enter new bug
Bug#: 32219
Product:  
Component:  
Status: UNCONFIRMED
Resolution:
Assigned To: Not yet assigned to anyone <unassigned@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Pawel Sikora <pluto@agmk.net>
Add CC:
CC:
Remove selected CCs
Build:
Patch URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 32219 depends on: 35513 Show dependency tree
Show dependency graph
Bug 32219 blocks:

Additional Comments:






Mark bug as waiting for feedback



    

    

View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: Opened: 2007-06-05 09:38
following testcase causes gpf on i386.

$ cat exe.c
extern void f() __attribute__((weak,visibility("hidden")));
extern int puts( char const* );
int main()
{
        f ? f() : puts( "f == null, skipped." );
        return 0;
}

$ gcc exe.c -fPIE --save-temps -m32 -O1 && ./a.out
Segmentation fault

this fails on i386 with gcc 3.4.5, 4.0, 4.1 and 4.2 (4.3 not tested).
x86_64 and ppc works fine, so it looks like a ix86 target bug.

------- Comment #1 From Pawel Sikora 2007-06-05 12:53 -------
btw, imho the weak+hidden is not a valid combination.
such symbol can't be resolved in runtime because it doesn't exist
in elf rel.plt/rel.dyn tables. it can be resolved only during
linking several objects into one piece (e.g. exec/shlib),
but in such case the weak+hidden behaves like plain hidden.

------- Comment #2 From Andrew Pinski 2007-06-05 13:30 -------
f always will bind local ...
Also you should be using -PIE when linking.

------- Comment #3 From Pawel Sikora 2007-06-05 14:10 -------
(In reply to comment #2)

> Also you should be using -PIE when linking.

hmm, it doesn't work with int main();

$ gcc -s main.c -fpie -Wl,-pie
/usr/bin/ld: /usr/lib64/crt1.o: relocation R_X86_64_32S against
`__libc_csu_fini' can not be used when making a shared object;
 recompile with -fPIC
/usr/lib64/crt1.o: could not read symbols: Bad value
collect2: ld returned 1 exit status

huh, glibc bug, linker bug?

------- Comment #4 From Pawel Sikora 2007-06-05 14:13 -------
(In reply to comment #2)
> f always will bind local ...

so, should gcc reject weak attribute in this (hidden visibility) case?

------- Comment #5 From Pawel Sikora 2008-02-23 21:09 -------
(In reply to comment #3)
> (In reply to comment #2)
> 
> > Also you should be using -PIE when linking.
> 
> hmm, it doesn't work with int main();
> 
> $ gcc -s main.c -fpie -Wl,-pie
> /usr/bin/ld: /usr/lib64/crt1.o: relocation R_X86_64_32S against
> `__libc_csu_fini' can not be used when making a shared object;
>  recompile with -fPIC
> /usr/lib64/crt1.o: could not read symbols: Bad value
> collect2: ld returned 1 exit status
> 
> huh, glibc bug, linker bug?

with gcc-4.2.3 and binutils-2.18.50.0.4 it links fine.

------- Comment #6 From H.J. Lu 2008-02-23 23:12 -------
Weak and hidden aren't really compatible. Linker should enforce it.
I opened a linker bug:

http://sourceware.org/bugzilla/show_bug.cgi?id=5789

As for gcc, I think it is OK since it is a user error and linker
should issue an error. Besides, gcc doesn't know if the .o
file will be used for PIE/shared library or normal executable.
The runtime error only happens with PIE/shared library, not
normal executable.

------- Comment #7 From H.J. Lu 2008-02-25 22:16 -------
It is a compiler bug after all. From:

http://groups.google.com/group/generic-abi/browse_thread/thread/4364eb484397ebe0

A hidden symbol must be defined in the same component, *if it is  
defined at all*. That last part is the key to the issue. In the case  
of a WEAK HIDDEN UNDEF symbol, it is possible for the symbol to remain  
undefined (or, looked at another way, it is possible for the symbol to  
be defined at link time as an absolute symbol with value 0). I agree  
with Daniel; the compiler should be aware of this possibility and  
generate code that will not require a dynamic relocation for this case.

For a weak and hidden symbol, it is bound local only if PIC is false or
it is used for branch. Otherwise, it should be treated with default
visibility.

------- Comment #8 From Matthieu CASTET 2009-12-29 23:20 -------
What's the status of this bug ?
The same things can happen in libraries with fpic

First Last Prev Next    No search results available      Search page      Enter new bug