From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10203 invoked by alias); 12 Apr 2011 08:57:30 -0000 Received: (qmail 10194 invoked by uid 22791); 12 Apr 2011 08:57:29 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Apr 2011 08:57:25 +0000 From: "nisse at lysator dot liu.se" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/48568] New: Missing documentation for __attribute__((visibility ("protected"))) on variables. X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: nisse at lysator dot liu.se X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Date: Tue, 12 Apr 2011 08:57:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-04/txt/msg01175.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D48568 Summary: Missing documentation for __attribute__((visibility ("protected"))) on variables. Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: nisse@lysator.liu.se I discovered that __attribute__((visibility ("protected"))) is supported on variables, not just on functions. This should be documented in the node "Variable Attributes" in the GCC manual This feature is useful in particular for accessing read-only tables (alloca= ted in the .rodata section) from PIC code. By default, access to such data in o= ther compilation units is done via the GOT table. Using the above attribute (and assuming that the definition is linked into in the same shared library file= ), the GOT lookup is omitted, and instead one gets a direct access via pc-rela= tive addressing. I was working on GNU/linux x86_64, where this corresponds to=20 .protected table lea table(%rip), %rax # To get the address of the table rather than the default mov table@GOTPCREL(%rip), %rax in assembler input. I admit I don't fully understand the .protected pseudo = op, but it's appearantly essential for getting the linker to do the right thing when linking the shared library (gcc -shared table-def.o table-use.o -o lib.so). Regards, /Niels M=C3=B6ller