Bug 599449

Summary: gcc hidden visibility doesn't work
Product: Red Hat Enterprise Linux 5 Reporter: Danny Feng <dfeng>
Component: gcc4Assignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: qe-baseos-tools-bugs
Severity: medium Docs Contact:
Priority: low    
Version: 5.6   
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2010-06-03 09:36:29 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Danny Feng 2010-06-03 09:26:38 UTC
Description of problem:
gcc hidden visibility doesn't work on rhel5. This blocks kernel build with hidden visibility. I've made a simplified reproduce step for it.

Version-Release number of selected component (if applicable):
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46)

How reproducible:
each time

Steps to Reproduce:
$ cat A.c
void hidden_fn(void) { return; }

$ cat B.c
extern void __attribute__((visibility("hidden"))) hidden_fn(void);
void fn(void) { hidden_fn(); }

$ cat C.c
extern void hidden_fn(void);
void fn(void) { hidden_fn(); }gcc -Wall -O2 -fPIC -c A.c -o A.o
$ gcc -Wall -O2 -fPIC -c B.c -o B.o
$ gcc -Wall -O2 -fPIC -c C.c -o C.o
$ gcc -Wall -O2 -shared -fPIC A.o B.o -o
  
Actual results:
/usr/bin/ld: B.o: relocation R_X86_64_PC32 against `hidden_fn' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value

Expected results:
pass compile

Additional info:
I'd like to know if there's a way to workaround this

Comment 1 Jakub Jelinek 2010-06-03 09:36:29 UTC
This is a user error.  If you declare some function with hidden visibility somewhere, you must also ensure that the definition has hidden visibility as well
(that can be done either by making sure the prototype with the hidden attribute
is in the CU that defines the function, or using the attribute also on the definition).