pie: Mark __export_*() functions as externally_visible

GCC's lto source:
> To avoid this problem the compiler must assume that it sees the
> whole program when doing link-time optimization.  Strictly
> speaking, the whole program is rarely visible even at link-time.
> Standard system libraries are usually linked dynamically or not
> provided with the link-time information.  In GCC, the whole
> program option (@option{-fwhole-program}) asserts that every
> function and variable defined in the current compilation
> unit is static, except for function @code{main} (note: at
> link time, the current unit is the union of all objects compiled
> with LTO).  Since some functions and variables need to
> be referenced externally, for example by another DSO or from an
> assembler file, GCC also provides the function and variable
> attribute @code{externally_visible} which can be used to disable
> the effect of @option{-fwhole-program} on a specific symbol.

As far as I read gcc's source, ipa_comdats() will avoid placing symbols
that are either already in a user-defined section or have
externally_visible attribute into new optimized gcc sections.

Signed-off-by: Dmitry Safonov <dima@arista.com>
Signed-off-by: Andrei Vagin <avagin@gmail.com>
This commit is contained in:
Dmitry Safonov 2022-02-14 11:47:30 +00:00 committed by Andrei Vagin
parent 5d6c8bc584
commit c9fdd355f6
2 changed files with 14 additions and 3 deletions

View file

@ -30,6 +30,17 @@
#define __always_unused __attribute__((unused))
#define __must_check __attribute__((__warn_unused_result__))
#ifndef __has_attribute
#define __has_attribute(x) 0
#endif
/* Not supported by clang */
#if __has_attribute(__externally_visible__)
#define __visible __attribute__((__externally_visible__))
#else
#define __visible
#endif
#define __section(S) __attribute__((__section__(#S)))
#ifndef __always_inline