Fix some minor prefixing misses on Linux.

These symbols are platform dependent and were not caught with testing on
macOS before.

Verification command on Linux:

$ cmake -GNinja -B build -DBORINGSSL_PREFIX=brlogenshfegle && ninja -C build
$ nm -AP build/libcrypto.a 2>/dev/null | grep -vE 'brlogenshfegle| [a-zU] | _Z[A-Z]*St| _Zn| _ZN9__gnu_cxx'

Bug: 42220000
Change-Id: I619f53456d3bd06d4da01993b31e3a6c6a6a6964
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/87307
Auto-Submit: Rudolf Polzer <rpolzer@google.com>
Reviewed-by: Xiangfei Ding <xfding@google.com>
Commit-Queue: Xiangfei Ding <xfding@google.com>
diff --git a/crypto/curve25519/internal.h b/crypto/curve25519/internal.h
index 10baede..c3bc6fe 100644
--- a/crypto/curve25519/internal.h
+++ b/crypto/curve25519/internal.h
@@ -33,8 +33,6 @@
     defined(__GNUC__) && defined(__x86_64__) && !defined(OPENSSL_WINDOWS)
 #define BORINGSSL_FE25519_ADX
 
-BSSL_NAMESPACE_END
-
 // fiat_curve25519_adx_mul is defined in
 // third_party/fiat/asm/fiat_curve25519_adx_mul.S
 extern "C" void __attribute__((sysv_abi)) fiat_curve25519_adx_mul(
@@ -46,13 +44,9 @@
     uint64_t out[4], const uint64_t in[4]);
 
 // x25519_scalar_mult_adx is defined in third_party/fiat/curve25519_64_adx.h
-extern "C" void x25519_scalar_mult_adx(uint8_t out[32],
-                                       const uint8_t scalar[32],
-                                       const uint8_t point[32]);
-extern "C" void x25519_ge_scalarmult_base_adx(uint8_t h[4][32],
-                                              const uint8_t a[32]);
-
-BSSL_NAMESPACE_BEGIN
+void x25519_scalar_mult_adx(uint8_t out[32], const uint8_t scalar[32],
+                            const uint8_t point[32]);
+void x25519_ge_scalarmult_base_adx(uint8_t h[4][32], const uint8_t a[32]);
 
 #endif
 
diff --git a/crypto/fipsmodule/aes/internal.h b/crypto/fipsmodule/aes/internal.h
index 99d5a14..a83864e 100644
--- a/crypto/fipsmodule/aes/internal.h
+++ b/crypto/fipsmodule/aes/internal.h
@@ -189,11 +189,9 @@
                                            const AES_KEY *vpaes);
 extern "C" void vpaes_decrypt_key_to_bsaes(AES_KEY *out_bsaes,
                                            const AES_KEY *vpaes);
-extern "C" void vpaes_ctr32_encrypt_blocks_with_bsaes(const uint8_t *in,
-                                                      uint8_t *out,
-                                                      size_t blocks,
-                                                      const AES_KEY *key,
-                                                      const uint8_t ivec[16]);
+void vpaes_ctr32_encrypt_blocks_with_bsaes(const uint8_t *in, uint8_t *out,
+                                           size_t blocks, const AES_KEY *key,
+                                           const uint8_t ivec[16]);
 #else
 inline int bsaes_capable() { return 0; }
 
@@ -442,7 +440,7 @@
 extern "C" void gcm_ghash_clmul(uint8_t Xi[16], const u128 Htable[16],
                                 const uint8_t *inp, size_t len);
 
-extern "C" void gcm_init_ssse3(u128 Htable[16], const uint64_t Xi[2]);
+void gcm_init_ssse3(u128 Htable[16], const uint64_t Xi[2]);
 extern "C" void gcm_gmult_ssse3(uint8_t Xi[16], const u128 Htable[16]);
 extern "C" void gcm_ghash_ssse3(uint8_t Xi[16], const u128 Htable[16],
                                 const uint8_t *in, size_t len);
diff --git a/crypto/fipsmodule/bn/rsaz_exp.cc.inc b/crypto/fipsmodule/bn/rsaz_exp.cc.inc
index d47b413..105daae 100644
--- a/crypto/fipsmodule/bn/rsaz_exp.cc.inc
+++ b/crypto/fipsmodule/bn/rsaz_exp.cc.inc
@@ -41,12 +41,12 @@
     0, 0, 1 << 22, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
     0, 0, 0,       0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
 
-void RSAZ_1024_mod_exp_avx2(BN_ULONG result_norm[16],
-                            const BN_ULONG base_norm[16],
-                            const BN_ULONG exponent[16],
-                            const BN_ULONG m_norm[16], const BN_ULONG RR[16],
-                            BN_ULONG k0,
-                            BN_ULONG storage[MOD_EXP_CTIME_STORAGE_LEN]) {
+void bssl::RSAZ_1024_mod_exp_avx2(BN_ULONG result_norm[16],
+                                  const BN_ULONG base_norm[16],
+                                  const BN_ULONG exponent[16],
+                                  const BN_ULONG m_norm[16],
+                                  const BN_ULONG RR[16], BN_ULONG k0,
+                                  BN_ULONG storage[MOD_EXP_CTIME_STORAGE_LEN]) {
   static_assert(MOD_EXP_CTIME_ALIGN % 64 == 0,
                 "MOD_EXP_CTIME_ALIGN is too small");
   assert((uintptr_t)storage % 64 == 0);
diff --git a/crypto/fipsmodule/bn/rsaz_exp.h b/crypto/fipsmodule/bn/rsaz_exp.h
index 6467141..9bd3cb9 100644
--- a/crypto/fipsmodule/bn/rsaz_exp.h
+++ b/crypto/fipsmodule/bn/rsaz_exp.h
@@ -22,17 +22,15 @@
 
 #include <openssl/bn.h>
 
-#include "internal.h"
 #include "../../internal.h"
+#include "internal.h"
 
-#if defined(__cplusplus)
-extern "C" {
-#endif
+
+BSSL_NAMESPACE_BEGIN
 
 #if !defined(OPENSSL_NO_ASM) && defined(OPENSSL_X86_64)
 #define RSAZ_ENABLED
 
-
 // RSAZ_1024_mod_exp_avx2 sets |result| to |base_norm| raised to |exponent|
 // modulo |m_norm|. |base_norm| must be fully-reduced and |exponent| must have
 // the high bit set (it is 1024 bits wide). |RR| and |k0| must be |RR| and |n0|,
@@ -66,32 +64,34 @@
 
 // rsaz_1024_norm2red_avx2 converts |norm| from |BIGNUM| to RSAZ representation
 // and writes the result to |red|.
-void rsaz_1024_norm2red_avx2(BN_ULONG red[40], const BN_ULONG norm[16]);
+extern "C" void rsaz_1024_norm2red_avx2(BN_ULONG red[40],
+                                        const BN_ULONG norm[16]);
 
 // rsaz_1024_mul_avx2 computes |a| * |b| mod |n| and writes the result to |ret|.
 // Inputs and outputs are in Montgomery form, using RSAZ's representation. |k|
 // is -|n|^-1 mod 2^64 or |n0| from |BN_MONT_CTX|.
-void rsaz_1024_mul_avx2(BN_ULONG ret[40], const BN_ULONG a[40],
-                        const BN_ULONG b[40], const BN_ULONG n[40], BN_ULONG k);
+extern "C" void rsaz_1024_mul_avx2(BN_ULONG ret[40], const BN_ULONG a[40],
+                                   const BN_ULONG b[40], const BN_ULONG n[40],
+                                   BN_ULONG k);
 
 // rsaz_1024_mul_avx2 computes |a|^(2*|count|) mod |n| and writes the result to
 // |ret|. Inputs and outputs are in Montgomery form, using RSAZ's
 // representation. |k| is -|n|^-1 mod 2^64 or |n0| from |BN_MONT_CTX|.
-void rsaz_1024_sqr_avx2(BN_ULONG ret[40], const BN_ULONG a[40],
-                        const BN_ULONG n[40], BN_ULONG k, int count);
+extern "C" void rsaz_1024_sqr_avx2(BN_ULONG ret[40], const BN_ULONG a[40],
+                                   const BN_ULONG n[40], BN_ULONG k, int count);
 
 // rsaz_1024_scatter5_avx2 stores |val| at index |i| of |tbl|. |i| must be
 // positive and at most 31. It is treated as public. Note the table only uses 18
 // |BN_ULONG|s per entry instead of 40. It packs two 29-bit limbs into each
 // |BN_ULONG| and only stores 36 limbs rather than the padded 40.
-void rsaz_1024_scatter5_avx2(BN_ULONG tbl[32 * 18], const BN_ULONG val[40],
-                             int i);
+extern "C" void rsaz_1024_scatter5_avx2(BN_ULONG tbl[32 * 18],
+                                        const BN_ULONG val[40], int i);
 
 // rsaz_1024_gather5_avx2 loads index |i| of |tbl| and writes it to |val|. |i|
 // must be positive and at most 31. It is treated as secret. |tbl| must be
 // aligned to 32 bytes.
-void rsaz_1024_gather5_avx2(BN_ULONG val[40], const BN_ULONG tbl[32 * 18],
-                            int i);
+extern "C" void rsaz_1024_gather5_avx2(BN_ULONG val[40],
+                                       const BN_ULONG tbl[32 * 18], int i);
 
 // rsaz_1024_red2norm_avx2 converts |red| from RSAZ to |BIGNUM| representation
 // and writes the result to |norm|. The result will be <= the modulus.
@@ -99,13 +99,11 @@
 // WARNING: The result of this operation may not be fully reduced. |norm| may be
 // the modulus instead of zero. This function should be followed by a call to
 // |bn_reduce_once|.
-void rsaz_1024_red2norm_avx2(BN_ULONG norm[16], const BN_ULONG red[40]);
-
+extern "C" void rsaz_1024_red2norm_avx2(BN_ULONG norm[16],
+                                        const BN_ULONG red[40]);
 
 #endif  // !OPENSSL_NO_ASM && OPENSSL_X86_64
 
-#if defined(__cplusplus)
-}  // extern C
-#endif
+BSSL_NAMESPACE_END
 
 #endif  // OPENSSL_HEADER_CRYPTO_FIPSMODULE_BN_RSAZ_EXP_H
diff --git a/crypto/poly1305/internal.h b/crypto/poly1305/internal.h
index 3447b4f..3909490 100644
--- a/crypto/poly1305/internal.h
+++ b/crypto/poly1305/internal.h
@@ -18,9 +18,8 @@
 #include <openssl/base.h>
 #include <openssl/poly1305.h>
 
-#if defined(__cplusplus)
-extern "C" {
-#endif
+
+BSSL_NAMESPACE_BEGIN
 
 #if defined(OPENSSL_ARM) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_APPLE)
 #define OPENSSL_POLY1305_NEON
@@ -33,9 +32,6 @@
 void CRYPTO_poly1305_finish_neon(poly1305_state *state, uint8_t mac[16]);
 #endif
 
-
-#if defined(__cplusplus)
-}  // extern C
-#endif
+BSSL_NAMESPACE_END
 
 #endif  // OPENSSL_HEADER_CRYPTO_POLY1305_INTERNAL_H
diff --git a/crypto/poly1305/poly1305_arm.cc b/crypto/poly1305/poly1305_arm.cc
index 318b657..210715c 100644
--- a/crypto/poly1305/poly1305_arm.cc
+++ b/crypto/poly1305/poly1305_arm.cc
@@ -24,9 +24,9 @@
 #include "internal.h"
 
 
-#if defined(OPENSSL_POLY1305_NEON)
+BSSL_NAMESPACE_BEGIN
 
-using namespace bssl;
+#if defined(OPENSSL_POLY1305_NEON)
 
 typedef struct {
   uint32_t v[12];  // for alignment; only using 10
@@ -310,3 +310,5 @@
 }
 
 #endif  // OPENSSL_POLY1305_NEON
+
+BSSL_NAMESPACE_END
diff --git a/gen/boringssl_prefix_symbols_c.inc b/gen/boringssl_prefix_symbols_c.inc
index 667f353..3236487 100644
--- a/gen/boringssl_prefix_symbols_c.inc
+++ b/gen/boringssl_prefix_symbols_c.inc
@@ -611,6 +611,7 @@
 #pragma redefine_extname CRYPTO_get_lock_name BORINGSSL_SYMBOL(BORINGSSL_ADD_PREFIX(CRYPTO_get_lock_name))
 #pragma redefine_extname CRYPTO_get_locking_callback BORINGSSL_SYMBOL(BORINGSSL_ADD_PREFIX(CRYPTO_get_locking_callback))
 #pragma redefine_extname CRYPTO_has_asm BORINGSSL_SYMBOL(BORINGSSL_ADD_PREFIX(CRYPTO_has_asm))
+#pragma redefine_extname CRYPTO_has_broken_NEON BORINGSSL_SYMBOL(BORINGSSL_ADD_PREFIX(CRYPTO_has_broken_NEON))
 #pragma redefine_extname CRYPTO_is_confidential_build BORINGSSL_SYMBOL(BORINGSSL_ADD_PREFIX(CRYPTO_is_confidential_build))
 #pragma redefine_extname CRYPTO_library_init BORINGSSL_SYMBOL(BORINGSSL_ADD_PREFIX(CRYPTO_library_init))
 #pragma redefine_extname CRYPTO_malloc BORINGSSL_SYMBOL(BORINGSSL_ADD_PREFIX(CRYPTO_malloc))
@@ -3667,6 +3668,7 @@
 #define CRYPTO_get_lock_name BORINGSSL_ADD_PREFIX(CRYPTO_get_lock_name)
 #define CRYPTO_get_locking_callback BORINGSSL_ADD_PREFIX(CRYPTO_get_locking_callback)
 #define CRYPTO_has_asm BORINGSSL_ADD_PREFIX(CRYPTO_has_asm)
+#define CRYPTO_has_broken_NEON BORINGSSL_ADD_PREFIX(CRYPTO_has_broken_NEON)
 #define CRYPTO_is_confidential_build BORINGSSL_ADD_PREFIX(CRYPTO_is_confidential_build)
 #define CRYPTO_library_init BORINGSSL_ADD_PREFIX(CRYPTO_library_init)
 #define CRYPTO_malloc BORINGSSL_ADD_PREFIX(CRYPTO_malloc)
diff --git a/third_party/fiat/curve25519_64_adx.h b/third_party/fiat/curve25519_64_adx.h
index 0c769eb..30e9ae9 100644
--- a/third_party/fiat/curve25519_64_adx.h
+++ b/third_party/fiat/curve25519_64_adx.h
@@ -14,14 +14,20 @@
   return a;
 }
 
-__attribute__((target("adx,bmi2")))
-static inline void fe4_mul(fe4 out, const fe4 x, const fe4 y) { fiat_curve25519_adx_mul(out, x, y); }
+__attribute__((target("adx,bmi2"))) static inline void fe4_mul(fe4 out,
+                                                               const fe4 x,
+                                                               const fe4 y) {
+  bssl::fiat_curve25519_adx_mul(out, x, y);
+}
 
-__attribute__((target("adx,bmi2")))
-static inline void fe4_sq(fe4 out, const fe4 x) { fiat_curve25519_adx_square(out, x); }
+__attribute__((target("adx,bmi2"))) static inline void fe4_sq(fe4 out,
+                                                              const fe4 x) {
+  bssl::fiat_curve25519_adx_square(out, x);
+}
 
 /*
- * The function fiat_mulx_u64 is a multiplication, returning the full double-width result.
+ * The function fiat_mulx_u64 is a multiplication, returning the full
+ * double-width result.
  *
  * Postconditions:
  *   out1 = (arg1 * arg2) mod 2^64
@@ -466,9 +472,8 @@
   fe4_mul(out, t1, t0);
 }
 
-__attribute__((target("adx,bmi2")))
-void x25519_scalar_mult_adx(uint8_t out[32], const uint8_t scalar[32],
-                            const uint8_t point[32]) {
+__attribute__((target("adx,bmi2"))) void bssl::x25519_scalar_mult_adx(
+    uint8_t out[32], const uint8_t scalar[32], const uint8_t point[32]) {
   uint8_t e[32];
   bssl::OPENSSL_memcpy(e, scalar, 32);
   e[0] &= 248;
@@ -646,8 +651,8 @@
 //
 // Preconditions:
 //   a[31] <= 127
-__attribute__((target("adx,bmi2")))
-void x25519_ge_scalarmult_base_adx(uint8_t h[4][32], const uint8_t a[32]) {
+__attribute__((target("adx,bmi2"))) void bssl::x25519_ge_scalarmult_base_adx(
+    uint8_t h[4][32], const uint8_t a[32]) {
   signed char e[64];
   signed char carry;
 
diff --git a/util/pregenerate/idextractor.go b/util/pregenerate/idextractor.go
index 8d35d3b..76b1161 100644
--- a/util/pregenerate/idextractor.go
+++ b/util/pregenerate/idextractor.go
@@ -32,6 +32,7 @@
 //
 // They will always be included in the prefixing headers.
 var platformDependentRedefineExtnameSymbols = []string{
+	"CRYPTO_has_broken_NEON",
 	"CRYPTO_needs_hwcap2_workaround",
 	"CRYPTO_set_fuzzer_mode",
 	"RAND_enable_fork_unsafe_buffering",
@@ -167,15 +168,19 @@
 			// Already in a namespace.
 			return nil
 		}
-		can_redefine_extname := true
+		canRedefineExtname := true
 		switch id.Linkage {
-		case "static", "static inline":
+		case "", "static", "static inline":
 			// Definitely not linked.
 			return nil
 		case `extern "C" inline`, `extern "C++" inline`:
 			// Sorry, can't redefine_extname inline functions:
 			// error: #pragma redefine_extname is applicable to external C declarations only; not applied to function
-			can_redefine_extname = false
+			canRedefineExtname = false
+		case `extern "C"`:
+			// Link those.
+		default:
+			return fmt.Errorf("unexpected linkage: %q", id.Linkage)
 		}
 		switch id.Tag {
 		case "enumerator", "typedef", "using":
@@ -186,7 +191,7 @@
 			// however cannot be namespaced as known callers forward declare them.
 			return nil
 		case "function", "var":
-			if can_redefine_extname {
+			if canRedefineExtname {
 				viaRedefineExtname[id.Symbol] = struct{}{}
 			} else {
 				viaMacro[id.Symbol] = struct{}{}