Bug 48568 - Missing documentation for __attribute__((visibility ("protected"))) on variables.
Summary: Missing documentation for __attribute__((visibility ("protected"))) on variab...
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
Keywords: documentation
Depends on:
Reported: 2011-04-12 08:57 UTC by Niels Möller
Modified: 2015-11-17 21:13 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


Note You need to log in before you can comment on or make changes to this bug.
Description Niels Möller 2011-04-12 08:57:16 UTC
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 (allocated in the .rodata section) from PIC code. By default, access to such data in other 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-relative addressing. I was working on GNU/linux x86_64, where this corresponds to 

  .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).

/Niels Möller
Comment 1 sandra 2015-11-17 21:07:47 UTC
Author: sandra
Date: Tue Nov 17 21:07:15 2015
New Revision: 230498

URL: https://gcc.gnu.org/viewcvs?rev=230498&root=gcc&view=rev
2015-11-17  Sandra Loosemore  <sandra@codesourcery.com>

	PR 48568
	* doc/extend.texi (Common Function Attributes) [visibility]:
	Add cross-references to matching variable and type attributes.
	(Common Variable Attributes) [visibility]: Add missing entry.

Comment 2 sandra 2015-11-17 21:13:04 UTC
Fixed on trunk now.