Hide CPU capability symbols in C.

Our assembly does not use the GOT to reference symbols, which means
references to visible symbols will often require a TEXTREL. This is
undesirable, so all assembly-referenced symbols should be hidden. CPU
capabilities are the only such symbols defined in C.

These symbols may be hidden by doing at least one of:

1. Build with -fvisibility=hidden
2. __attribute__((visibility("hidden"))) in C.
3. .extern + .hidden in some assembly file referencing the symbol.

We have lots of consumers and can't always rely on (1) happening. We
were doing (3) by way of d216b71f909fe56255813dab0a8d052534bdcb91 and
16e38b2b8f50a3d048f61d2979d5ceddacd70fc3, but missed 32-bit x86 because
it doesn't cause a linker error.

Those two patches are not in upstream. Upstream instead does (3) by way
of x86cpuid.pl and friends, but we have none of these files.

Standardize on doing (2). This avoids accidentally getting TEXTRELs on
some 32-bit x86 build configurations.  This also undoes
d216b71f909fe56255813dab0a8d052534bdcb91 and
16e38b2b8f50a3d048f61d2979d5ceddacd70fc3. They are no now longer needed
and reduce the upstream diff.

Change-Id: Ib51c43fce6a7d8292533635e5d85d3c197a93644
Reviewed-on: https://boringssl-review.googlesource.com/22064
Commit-Queue: Matt Braithwaite <mab@google.com>
Reviewed-by: Matt Braithwaite <mab@google.com>
CQ-Verified: CQ bot account: commit-bot@chromium.org <commit-bot@chromium.org>
This commit is contained in:
David Benjamin 2017-10-18 22:23:09 -04:00 committed by CQ bot account: commit-bot@chromium.org
parent 3b358b25b0
commit 38636aba74
6 changed files with 17 additions and 13 deletions

View File

@ -40,6 +40,18 @@
OPENSSL_ARM || OPENSSL_AARCH64) */
// Our assembly does not use the GOT to reference symbols, which means
// references to visible symbols will often require a TEXTREL. This is
// undesirable, so all assembly-referenced symbols should be hidden. CPU
// capabilities are the only such symbols defined in C. Explicitly hide them,
// rather than rely on being built with -fvisibility=hidden.
#if defined(OPENSSL_WINDOWS)
#define HIDDEN
#else
#define HIDDEN __attribute__((visibility("hidden")))
#endif
// The capability variables are defined in this file in order to work around a
// linker bug. When linking with a .a, if no symbols in a .o are referenced
// then the .o is discarded, even if it has constructor functions.
@ -57,11 +69,11 @@
// archive, linking on OS X will fail to resolve common symbols. By
// initialising it to zero, it becomes a "data symbol", which isn't so
// affected.
uint32_t OPENSSL_ia32cap_P[4] = {0};
HIDDEN uint32_t OPENSSL_ia32cap_P[4] = {0};
#elif defined(OPENSSL_PPC64LE)
unsigned long OPENSSL_ppc64le_hwcap2 = 0;
HIDDEN unsigned long OPENSSL_ppc64le_hwcap2 = 0;
#elif defined(OPENSSL_ARM) || defined(OPENSSL_AARCH64)
@ -69,7 +81,7 @@ unsigned long OPENSSL_ppc64le_hwcap2 = 0;
#if defined(OPENSSL_STATIC_ARMCAP)
uint32_t OPENSSL_armcap_P =
HIDDEN uint32_t OPENSSL_armcap_P =
#if defined(OPENSSL_STATIC_ARMCAP_NEON) || defined(__ARM_NEON__)
ARMV7_NEON |
#endif
@ -88,7 +100,7 @@ uint32_t OPENSSL_armcap_P =
0;
#else
uint32_t OPENSSL_armcap_P = 0;
HIDDEN uint32_t OPENSSL_armcap_P = 0;
#endif
#endif

View File

@ -740,7 +740,6 @@ $code.=<<___;
.align 2
#if __ARM_MAX_ARCH__>=7
.comm OPENSSL_armcap_P,4,4
.hidden OPENSSL_armcap_P
#endif
___

View File

@ -698,7 +698,6 @@ ___
$code.=<<___;
#if __ARM_MAX_ARCH__>=7
.comm OPENSSL_armcap_P,4,4
.hidden OPENSSL_armcap_P
#endif
___

View File

@ -684,7 +684,6 @@ $code.=<<___;
.align 2
#if __ARM_MAX_ARCH__>=7 && !defined(__KERNEL__)
.comm OPENSSL_armcap_P,4,4
.hidden OPENSSL_armcap_P
#endif
___

View File

@ -649,7 +649,6 @@ $code.=<<___;
.align 2
#if __ARM_MAX_ARCH__>=7 && !defined(__KERNEL__)
.comm OPENSSL_armcap_P,4,4
.hidden OPENSSL_armcap_P
#endif
___

View File

@ -753,11 +753,7 @@ my %globals;
$self->{value} = $dir . "\t" . $$line;
if ($dir =~ /\.extern/) {
if ($flavour eq "elf") {
$self->{value} .= "\n.hidden $$line";
} else {
$self->{value} = "";
}
$self->{value} = ""; # swallow extern
} elsif (!$elf && $dir =~ /\.type/) {
$self->{value} = "";
$self->{value} = ".def\t" . ($globals{$1} or $1) . ";\t" .