Integrate the new way of asm symbol prefixing with CMake.

Update-Note: asm files now use relative paths to find their prefixing
include, and boringssl_prefix_symbols CMake target is gone now. Likely
no impact, but mentioning anyway just in case this CL causes a build
failure.

Bug: 42220000
Change-Id: I1f5c03e76b27b9522be7e93d95fa6c946a6a6964
Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/87268
Reviewed-by: Xiangfei Ding <xfding@google.com>
Commit-Queue: Rudolf Polzer <rpolzer@google.com>
diff --git a/BUILDING.md b/BUILDING.md
index f21dbd3..96e08e6 100644
--- a/BUILDING.md
+++ b/BUILDING.md
@@ -119,25 +119,15 @@
 
 BoringSSL's build system has experimental support for adding a custom prefix to
 all symbols. This can be useful when linking multiple versions of BoringSSL in
-the same project to avoid symbol conflicts. Symbol prefixing requires the most
-recent stable version of [Go](https://go.dev/).
+the same project to avoid symbol conflicts.
 
 In order to build with prefixed symbols, the `BORINGSSL_PREFIX` CMake variable
-should specify the prefix to add to all symbols, and the
-`BORINGSSL_PREFIX_SYMBOLS` CMake variable should specify the path to a file
-which contains a list of symbols which should be prefixed (one per line;
-comments are supported with `#`). In other words, `cmake -B build
--DBORINGSSL_PREFIX=MY_CUSTOM_PREFIX
--DBORINGSSL_PREFIX_SYMBOLS=/path/to/symbols.txt` will configure the build to add
-the prefix `MY_CUSTOM_PREFIX` to all of the symbols listed in
-`/path/to/symbols.txt`.
+should specify the prefix to add to all symbols. In other words, `cmake -B build
+-DBORINGSSL_PREFIX=MY_CUSTOM_PREFIX` will configure the build to add
+the prefix `MY_CUSTOM_PREFIX` to all of the symbols defined by the library.
 
-It is currently the caller's responsibility to create and maintain the list of
-symbols to be prefixed. Alternatively, `util/read_symbols.go` reads the list of
-exported symbols from a `.a` file, and can be used in a build script to generate
-the symbol list on the fly (by building without prefixing, using
-`read_symbols.go` to construct a symbol list, and then building again with
-prefixing).
+Note that symbol prefixing cannot be used with the combination of FIPS and
+static libraries.
 
 This mechanism is under development and may change over time. Please contact the
 BoringSSL maintainers if making use of it.
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6917223..f6485fd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -75,39 +75,17 @@
          "${${VAR}_RELEASE}")
 endforeach()
 
-if(BORINGSSL_PREFIX AND BORINGSSL_PREFIX_SYMBOLS)
+if(BORINGSSL_PREFIX)
   if(FIPS AND NOT BUILD_SHARED_LIBS)
     # Symbol prefixing is currently incompatible with delocate.
     message(FATAL_ERROR "Cannot use BORINGSSL_PREFIX with FIPS and static libraries")
   endif()
-  require_go()
+
   add_definitions(-DBORINGSSL_PREFIX=${BORINGSSL_PREFIX})
+
   # CMake automatically connects include_directories to the NASM command-line,
   # but not add_definitions.
   set(CMAKE_ASM_NASM_FLAGS "${CMAKE_ASM_NASM_FLAGS} -DBORINGSSL_PREFIX=${BORINGSSL_PREFIX}")
-
-  # Use "symbol_prefix_include" to store generated header files
-  include_directories(${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include)
-  add_custom_command(
-    OUTPUT symbol_prefix_include/boringssl_prefix_symbols.h
-           symbol_prefix_include/boringssl_prefix_symbols_asm.h
-           symbol_prefix_include/boringssl_prefix_symbols_nasm.inc
-    COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include
-    COMMAND ${GO_EXECUTABLE} run ${CMAKE_CURRENT_SOURCE_DIR}/util/make_prefix_headers.go -out ${CMAKE_CURRENT_BINARY_DIR}/symbol_prefix_include ${BORINGSSL_PREFIX_SYMBOLS}
-    DEPENDS util/make_prefix_headers.go
-            ${BORINGSSL_PREFIX_SYMBOLS})
-
-  # add_dependencies needs a target, not a file, so we add an intermediate
-  # target.
-  add_custom_target(
-    boringssl_prefix_symbols
-    DEPENDS symbol_prefix_include/boringssl_prefix_symbols.h
-            symbol_prefix_include/boringssl_prefix_symbols_asm.h
-            symbol_prefix_include/boringssl_prefix_symbols_nasm.inc)
-elseif(BORINGSSL_PREFIX OR BORINGSSL_PREFIX_SYMBOLS)
-  message(FATAL_ERROR "Must specify both or neither of BORINGSSL_PREFIX and BORINGSSL_PREFIX_SYMBOLS")
-else()
-  add_custom_target(boringssl_prefix_symbols)
 endif()
 
 if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
@@ -578,7 +556,6 @@
   add_library(bcm_c_generated_asm STATIC ${BCM_SOURCES})
   # The C++ code in libcrypto shouldn't depend on libstdc++.
   target_compile_options(bcm_c_generated_asm PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${NO_CXX_RUNTIME_FLAGS}> "-S")
-  add_dependencies(bcm_c_generated_asm boringssl_prefix_symbols)
   target_include_directories(bcm_c_generated_asm PRIVATE ${PROJECT_SOURCE_DIR}/include)
   set_target_properties(bcm_c_generated_asm PROPERTIES POSITION_INDEPENDENT_CODE ON)
   if(CLANG)
@@ -638,7 +615,6 @@
   add_library(bcm_library STATIC ${BCM_SOURCES} ${BCM_SOURCES_ASM_USED})
   # The C++ code in libcrypto shouldn't depend on libstdc++.
   target_compile_options(bcm_library PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${NO_CXX_RUNTIME_FLAGS}>)
-  add_dependencies(bcm_library boringssl_prefix_symbols)
   target_include_directories(bcm_library PRIVATE ${PROJECT_SOURCE_DIR}/include)
 
   add_custom_command(
@@ -652,7 +628,6 @@
   add_library(fipsmodule OBJECT ${BCM_SOURCES} ${BCM_SOURCES_ASM_USED})
   # The C++ code in libcrypto shouldn't depend on libstdc++.
   target_compile_options(fipsmodule PRIVATE $<$<COMPILE_LANGUAGE:CXX>:${NO_CXX_RUNTIME_FLAGS}>)
-  add_dependencies(fipsmodule boringssl_prefix_symbols)
   target_include_directories(fipsmodule PRIVATE ${PROJECT_SOURCE_DIR}/include)
   set(CRYPTO_FIPS_OBJECTS $<TARGET_OBJECTS:fipsmodule>)
 endif()
@@ -682,7 +657,6 @@
   )
 endif()
 
-add_dependencies(crypto boringssl_prefix_symbols)
 if(WIN32)
   target_link_libraries(crypto ws2_32)
 endif()
diff --git a/crypto/internal.h b/crypto/internal.h
index 1a5ea4b..287bb6d 100644
--- a/crypto/internal.h
+++ b/crypto/internal.h
@@ -15,6 +15,7 @@
 #ifndef OPENSSL_HEADER_CRYPTO_INTERNAL_H
 #define OPENSSL_HEADER_CRYPTO_INTERNAL_H
 
+#include <openssl/base.h>
 #include <openssl/crypto.h>
 #include <openssl/ex_data.h>
 #include <openssl/stack.h>
@@ -58,6 +59,10 @@
 #include "intrin.h"
 #endif
 
+#if defined(BORINGSSL_PREFIX)
+#include <openssl/prefix_symbols_internal_c.h>
+#endif
+
 
 BSSL_NAMESPACE_BEGIN
 
diff --git a/crypto/perlasm/x86_64-xlate.pl b/crypto/perlasm/x86_64-xlate.pl
index 0955c86..92d3d62 100755
--- a/crypto/perlasm/x86_64-xlate.pl
+++ b/crypto/perlasm/x86_64-xlate.pl
@@ -1342,7 +1342,7 @@
 \%define _CET_ENDBR
 
 \%ifdef BORINGSSL_PREFIX
-\%include "boringssl_prefix_symbols_nasm.inc"
+\%include "@{[ '../' x ($0 =~ m![/\\]!g) ]}boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 \%endif
 ___
 } elsif ($masm) {
diff --git a/crypto/perlasm/x86asm.pl b/crypto/perlasm/x86asm.pl
index 70007a0..fd91d3c 100644
--- a/crypto/perlasm/x86asm.pl
+++ b/crypto/perlasm/x86asm.pl
@@ -292,7 +292,7 @@
     if ($win32) {
         print <<___ unless $masm;
 \%ifdef BORINGSSL_PREFIX
-\%include "boringssl_prefix_symbols_nasm.inc"
+\%include "@{[ '../' x ($0 =~ m![/\\]!g) ]}boringssl_prefix_symbols_internal_x86_win_asm.inc"
 \%endif
 \%ifidn __OUTPUT_FORMAT__, win32
 ___
diff --git a/gen/bcm/aes-gcm-avx2-x86_64-win.asm b/gen/bcm/aes-gcm-avx2-x86_64-win.asm
index ca1d28b..583f6b8 100644
--- a/gen/bcm/aes-gcm-avx2-x86_64-win.asm
+++ b/gen/bcm/aes-gcm-avx2-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.rdata rdata align=8
 ALIGN	16
diff --git a/gen/bcm/aes-gcm-avx512-x86_64-win.asm b/gen/bcm/aes-gcm-avx512-x86_64-win.asm
index 3a86e3a..4614875 100644
--- a/gen/bcm/aes-gcm-avx512-x86_64-win.asm
+++ b/gen/bcm/aes-gcm-avx512-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.rdata rdata align=8
 ALIGN	64
diff --git a/gen/bcm/aesni-gcm-x86_64-win.asm b/gen/bcm/aesni-gcm-x86_64-win.asm
index e8324d2..4c185e9 100644
--- a/gen/bcm/aesni-gcm-x86_64-win.asm
+++ b/gen/bcm/aesni-gcm-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/bcm/aesni-x86-win.asm b/gen/bcm/aesni-x86-win.asm
index 35f1d8e..0a422a1 100644
--- a/gen/bcm/aesni-x86-win.asm
+++ b/gen/bcm/aesni-x86-win.asm
@@ -2,7 +2,7 @@
 ; source tree. Do not edit by hand.
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_win_asm.inc"
 %endif
 %ifidn __OUTPUT_FORMAT__, win32
 %ifidn __OUTPUT_FORMAT__,obj
diff --git a/gen/bcm/aesni-x86_64-win.asm b/gen/bcm/aesni-x86_64-win.asm
index 8e592cd..99adbb5 100644
--- a/gen/bcm/aesni-x86_64-win.asm
+++ b/gen/bcm/aesni-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/bcm/bn-586-win.asm b/gen/bcm/bn-586-win.asm
index fd3fe01..b806ae9 100644
--- a/gen/bcm/bn-586-win.asm
+++ b/gen/bcm/bn-586-win.asm
@@ -2,7 +2,7 @@
 ; source tree. Do not edit by hand.
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_win_asm.inc"
 %endif
 %ifidn __OUTPUT_FORMAT__, win32
 %ifidn __OUTPUT_FORMAT__,obj
diff --git a/gen/bcm/co-586-win.asm b/gen/bcm/co-586-win.asm
index 6ad4696..3cf3d61 100644
--- a/gen/bcm/co-586-win.asm
+++ b/gen/bcm/co-586-win.asm
@@ -2,7 +2,7 @@
 ; source tree. Do not edit by hand.
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_win_asm.inc"
 %endif
 %ifidn __OUTPUT_FORMAT__, win32
 %ifidn __OUTPUT_FORMAT__,obj
diff --git a/gen/bcm/ghash-ssse3-x86-win.asm b/gen/bcm/ghash-ssse3-x86-win.asm
index 201ef57..f31a1ae 100644
--- a/gen/bcm/ghash-ssse3-x86-win.asm
+++ b/gen/bcm/ghash-ssse3-x86-win.asm
@@ -2,7 +2,7 @@
 ; source tree. Do not edit by hand.
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_win_asm.inc"
 %endif
 %ifidn __OUTPUT_FORMAT__, win32
 %ifidn __OUTPUT_FORMAT__,obj
diff --git a/gen/bcm/ghash-ssse3-x86_64-win.asm b/gen/bcm/ghash-ssse3-x86_64-win.asm
index 5bcd094..7e22724 100644
--- a/gen/bcm/ghash-ssse3-x86_64-win.asm
+++ b/gen/bcm/ghash-ssse3-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/bcm/ghash-x86-win.asm b/gen/bcm/ghash-x86-win.asm
index 3f6c707..c06deee 100644
--- a/gen/bcm/ghash-x86-win.asm
+++ b/gen/bcm/ghash-x86-win.asm
@@ -2,7 +2,7 @@
 ; source tree. Do not edit by hand.
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_win_asm.inc"
 %endif
 %ifidn __OUTPUT_FORMAT__, win32
 %ifidn __OUTPUT_FORMAT__,obj
diff --git a/gen/bcm/ghash-x86_64-win.asm b/gen/bcm/ghash-x86_64-win.asm
index 5cfb844..d6a30c0 100644
--- a/gen/bcm/ghash-x86_64-win.asm
+++ b/gen/bcm/ghash-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/bcm/p256-x86_64-asm-win.asm b/gen/bcm/p256-x86_64-asm-win.asm
index 194df1c..1ead815 100644
--- a/gen/bcm/p256-x86_64-asm-win.asm
+++ b/gen/bcm/p256-x86_64-asm-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/bcm/p256_beeu-x86_64-asm-win.asm b/gen/bcm/p256_beeu-x86_64-asm-win.asm
index 7c7da68..df6c719 100644
--- a/gen/bcm/p256_beeu-x86_64-asm-win.asm
+++ b/gen/bcm/p256_beeu-x86_64-asm-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/bcm/rdrand-x86_64-win.asm b/gen/bcm/rdrand-x86_64-win.asm
index 6dba87b..72132c7 100644
--- a/gen/bcm/rdrand-x86_64-win.asm
+++ b/gen/bcm/rdrand-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/bcm/rsaz-avx2-win.asm b/gen/bcm/rsaz-avx2-win.asm
index beadbdd..3a3c14e 100644
--- a/gen/bcm/rsaz-avx2-win.asm
+++ b/gen/bcm/rsaz-avx2-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/bcm/sha1-586-win.asm b/gen/bcm/sha1-586-win.asm
index c8823a9..3de0ff9 100644
--- a/gen/bcm/sha1-586-win.asm
+++ b/gen/bcm/sha1-586-win.asm
@@ -2,7 +2,7 @@
 ; source tree. Do not edit by hand.
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_win_asm.inc"
 %endif
 %ifidn __OUTPUT_FORMAT__, win32
 %ifidn __OUTPUT_FORMAT__,obj
diff --git a/gen/bcm/sha1-x86_64-win.asm b/gen/bcm/sha1-x86_64-win.asm
index c5da333..78c06cb 100644
--- a/gen/bcm/sha1-x86_64-win.asm
+++ b/gen/bcm/sha1-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/bcm/sha256-586-win.asm b/gen/bcm/sha256-586-win.asm
index 0ef244d..2b1e7ea 100644
--- a/gen/bcm/sha256-586-win.asm
+++ b/gen/bcm/sha256-586-win.asm
@@ -2,7 +2,7 @@
 ; source tree. Do not edit by hand.
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_win_asm.inc"
 %endif
 %ifidn __OUTPUT_FORMAT__, win32
 %ifidn __OUTPUT_FORMAT__,obj
diff --git a/gen/bcm/sha256-x86_64-win.asm b/gen/bcm/sha256-x86_64-win.asm
index b720603..8552491 100644
--- a/gen/bcm/sha256-x86_64-win.asm
+++ b/gen/bcm/sha256-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/bcm/sha512-586-win.asm b/gen/bcm/sha512-586-win.asm
index 2f43a1c..4412b0d 100644
--- a/gen/bcm/sha512-586-win.asm
+++ b/gen/bcm/sha512-586-win.asm
@@ -2,7 +2,7 @@
 ; source tree. Do not edit by hand.
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_win_asm.inc"
 %endif
 %ifidn __OUTPUT_FORMAT__, win32
 %ifidn __OUTPUT_FORMAT__,obj
diff --git a/gen/bcm/sha512-x86_64-win.asm b/gen/bcm/sha512-x86_64-win.asm
index 3b02e03..cbaed01 100644
--- a/gen/bcm/sha512-x86_64-win.asm
+++ b/gen/bcm/sha512-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/bcm/vpaes-x86-win.asm b/gen/bcm/vpaes-x86-win.asm
index 3f087e1..30e2f4e 100644
--- a/gen/bcm/vpaes-x86-win.asm
+++ b/gen/bcm/vpaes-x86-win.asm
@@ -2,7 +2,7 @@
 ; source tree. Do not edit by hand.
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_win_asm.inc"
 %endif
 %ifidn __OUTPUT_FORMAT__, win32
 %ifidn __OUTPUT_FORMAT__,obj
diff --git a/gen/bcm/vpaes-x86_64-win.asm b/gen/bcm/vpaes-x86_64-win.asm
index e28ae47..3b7b117 100644
--- a/gen/bcm/vpaes-x86_64-win.asm
+++ b/gen/bcm/vpaes-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/bcm/x86-mont-win.asm b/gen/bcm/x86-mont-win.asm
index f9d12bb..a956507 100644
--- a/gen/bcm/x86-mont-win.asm
+++ b/gen/bcm/x86-mont-win.asm
@@ -2,7 +2,7 @@
 ; source tree. Do not edit by hand.
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_win_asm.inc"
 %endif
 %ifidn __OUTPUT_FORMAT__, win32
 %ifidn __OUTPUT_FORMAT__,obj
diff --git a/gen/bcm/x86_64-mont-win.asm b/gen/bcm/x86_64-mont-win.asm
index c768d16..fa8b728 100644
--- a/gen/bcm/x86_64-mont-win.asm
+++ b/gen/bcm/x86_64-mont-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/bcm/x86_64-mont5-win.asm b/gen/bcm/x86_64-mont5-win.asm
index 5ddeb86..43ddd24 100644
--- a/gen/bcm/x86_64-mont5-win.asm
+++ b/gen/bcm/x86_64-mont5-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/boringssl_prefix_symbols_internal_x86_64_asm.inc b/gen/boringssl_prefix_symbols_internal_x86_64_win_asm.inc
similarity index 98%
rename from gen/boringssl_prefix_symbols_internal_x86_64_asm.inc
rename to gen/boringssl_prefix_symbols_internal_x86_64_win_asm.inc
index 5a20a2f..0f3aab2 100644
--- a/gen/boringssl_prefix_symbols_internal_x86_64_asm.inc
+++ b/gen/boringssl_prefix_symbols_internal_x86_64_win_asm.inc
@@ -14,6 +14,10 @@
 
 ; Generated by go ./util/pregenerate. Do not edit manually.
 
+%ifndef OPENSSL_HEADER_GEN_BORINGSSL_PREFIX_SYMBOLS_INTERNAL_X86_64_WIN_ASM_H
+%define OPENSSL_HEADER_GEN_BORINGSSL_PREFIX_SYMBOLS_INTERNAL_X86_64_WIN_ASM_H
+
+
 %define BORINGSSL_function_hit BORINGSSL_PREFIX %+ _BORINGSSL_function_hit
 %define CRYPTO_rdrand BORINGSSL_PREFIX %+ _CRYPTO_rdrand
 %define CRYPTO_rdrand_multiple8_buf BORINGSSL_PREFIX %+ _CRYPTO_rdrand_multiple8_buf
@@ -311,3 +315,5 @@
 %define vpaes_set_decrypt_key BORINGSSL_PREFIX %+ _vpaes_set_decrypt_key
 %define vpaes_set_encrypt_key BORINGSSL_PREFIX %+ _vpaes_set_encrypt_key
 %define x25519_NEON BORINGSSL_PREFIX %+ _x25519_NEON
+
+%endif  ; OPENSSL_HEADER_GEN_BORINGSSL_PREFIX_SYMBOLS_INTERNAL_X86_64_WIN_ASM_H
diff --git a/gen/boringssl_prefix_symbols_internal_x86_asm.inc b/gen/boringssl_prefix_symbols_internal_x86_win_asm.inc
similarity index 98%
rename from gen/boringssl_prefix_symbols_internal_x86_asm.inc
rename to gen/boringssl_prefix_symbols_internal_x86_win_asm.inc
index 49531e6..79ad399 100644
--- a/gen/boringssl_prefix_symbols_internal_x86_asm.inc
+++ b/gen/boringssl_prefix_symbols_internal_x86_win_asm.inc
@@ -14,6 +14,10 @@
 
 ; Generated by go ./util/pregenerate. Do not edit manually.
 
+%ifndef OPENSSL_HEADER_GEN_BORINGSSL_PREFIX_SYMBOLS_INTERNAL_X86_WIN_ASM_H
+%define OPENSSL_HEADER_GEN_BORINGSSL_PREFIX_SYMBOLS_INTERNAL_X86_WIN_ASM_H
+
+
 %define _BORINGSSL_function_hit _ %+ BORINGSSL_PREFIX %+ _BORINGSSL_function_hit
 %define _CRYPTO_rdrand _ %+ BORINGSSL_PREFIX %+ _CRYPTO_rdrand
 %define _CRYPTO_rdrand_multiple8_buf _ %+ BORINGSSL_PREFIX %+ _CRYPTO_rdrand_multiple8_buf
@@ -311,3 +315,5 @@
 %define _vpaes_set_decrypt_key _ %+ BORINGSSL_PREFIX %+ _vpaes_set_decrypt_key
 %define _vpaes_set_encrypt_key _ %+ BORINGSSL_PREFIX %+ _vpaes_set_encrypt_key
 %define _x25519_NEON _ %+ BORINGSSL_PREFIX %+ _x25519_NEON
+
+%endif  ; OPENSSL_HEADER_GEN_BORINGSSL_PREFIX_SYMBOLS_INTERNAL_X86_WIN_ASM_H
diff --git a/gen/crypto/aes128gcmsiv-x86_64-win.asm b/gen/crypto/aes128gcmsiv-x86_64-win.asm
index 6691a2d..6d8a1b2 100644
--- a/gen/crypto/aes128gcmsiv-x86_64-win.asm
+++ b/gen/crypto/aes128gcmsiv-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.rdata rdata align=8
 
diff --git a/gen/crypto/chacha-x86-win.asm b/gen/crypto/chacha-x86-win.asm
index d709da0..565c9f5 100644
--- a/gen/crypto/chacha-x86-win.asm
+++ b/gen/crypto/chacha-x86-win.asm
@@ -2,7 +2,7 @@
 ; source tree. Do not edit by hand.
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_win_asm.inc"
 %endif
 %ifidn __OUTPUT_FORMAT__, win32
 %ifidn __OUTPUT_FORMAT__,obj
diff --git a/gen/crypto/chacha-x86_64-win.asm b/gen/crypto/chacha-x86_64-win.asm
index f9cae3f..2f7490a 100644
--- a/gen/crypto/chacha-x86_64-win.asm
+++ b/gen/crypto/chacha-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/crypto/chacha20_poly1305_x86_64-win.asm b/gen/crypto/chacha20_poly1305_x86_64-win.asm
index 7ff65db..40ef631 100644
--- a/gen/crypto/chacha20_poly1305_x86_64-win.asm
+++ b/gen/crypto/chacha20_poly1305_x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.rdata rdata align=8
 ALIGN	64
diff --git a/gen/crypto/md5-586-win.asm b/gen/crypto/md5-586-win.asm
index 25592b8..3c0f1e5 100644
--- a/gen/crypto/md5-586-win.asm
+++ b/gen/crypto/md5-586-win.asm
@@ -2,7 +2,7 @@
 ; source tree. Do not edit by hand.
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_win_asm.inc"
 %endif
 %ifidn __OUTPUT_FORMAT__, win32
 %ifidn __OUTPUT_FORMAT__,obj
diff --git a/gen/crypto/md5-x86_64-win.asm b/gen/crypto/md5-x86_64-win.asm
index f6c5b62..89a7e44 100644
--- a/gen/crypto/md5-x86_64-win.asm
+++ b/gen/crypto/md5-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/gen/sources.bzl b/gen/sources.bzl
index b0346cb..68b393c 100644
--- a/gen/sources.bzl
+++ b/gen/sources.bzl
@@ -686,7 +686,11 @@
     "crypto/spake2plus/internal.h",
     "crypto/trust_token/internal.h",
     "crypto/x509/internal.h",
+    "gen/boringssl_prefix_symbols_internal_x86_64_win_asm.inc",
+    "gen/boringssl_prefix_symbols_internal_x86_win_asm.inc",
     "include/openssl/prefix_symbols.h",
+    "include/openssl/prefix_symbols_internal_S.h",
+    "include/openssl/prefix_symbols_internal_c.h",
     "third_party/fiat/bedrock_unverified_bareminimum.c.inc",
     "third_party/fiat/bedrock_unverified_platform.c.inc",
     "third_party/fiat/curve25519_32.h",
diff --git a/gen/sources.cmake b/gen/sources.cmake
index d862eef..76e4935 100644
--- a/gen/sources.cmake
+++ b/gen/sources.cmake
@@ -708,7 +708,11 @@
   crypto/spake2plus/internal.h
   crypto/trust_token/internal.h
   crypto/x509/internal.h
+  gen/boringssl_prefix_symbols_internal_x86_64_win_asm.inc
+  gen/boringssl_prefix_symbols_internal_x86_win_asm.inc
   include/openssl/prefix_symbols.h
+  include/openssl/prefix_symbols_internal_S.h
+  include/openssl/prefix_symbols_internal_c.h
   third_party/fiat/bedrock_unverified_bareminimum.c.inc
   third_party/fiat/bedrock_unverified_platform.c.inc
   third_party/fiat/curve25519_32.h
diff --git a/gen/sources.gni b/gen/sources.gni
index 56ca0c8..1b7aa00 100644
--- a/gen/sources.gni
+++ b/gen/sources.gni
@@ -686,7 +686,11 @@
   "crypto/spake2plus/internal.h",
   "crypto/trust_token/internal.h",
   "crypto/x509/internal.h",
+  "gen/boringssl_prefix_symbols_internal_x86_64_win_asm.inc",
+  "gen/boringssl_prefix_symbols_internal_x86_win_asm.inc",
   "include/openssl/prefix_symbols.h",
+  "include/openssl/prefix_symbols_internal_S.h",
+  "include/openssl/prefix_symbols_internal_c.h",
   "third_party/fiat/bedrock_unverified_bareminimum.c.inc",
   "third_party/fiat/bedrock_unverified_platform.c.inc",
   "third_party/fiat/curve25519_32.h",
diff --git a/gen/sources.json b/gen/sources.json
index dad4298..ce8185a 100644
--- a/gen/sources.json
+++ b/gen/sources.json
@@ -668,7 +668,11 @@
       "crypto/spake2plus/internal.h",
       "crypto/trust_token/internal.h",
       "crypto/x509/internal.h",
+      "gen/boringssl_prefix_symbols_internal_x86_64_win_asm.inc",
+      "gen/boringssl_prefix_symbols_internal_x86_win_asm.inc",
       "include/openssl/prefix_symbols.h",
+      "include/openssl/prefix_symbols_internal_S.h",
+      "include/openssl/prefix_symbols_internal_c.h",
       "third_party/fiat/bedrock_unverified_bareminimum.c.inc",
       "third_party/fiat/bedrock_unverified_platform.c.inc",
       "third_party/fiat/curve25519_32.h",
diff --git a/gen/sources.mk b/gen/sources.mk
index 0d1d104..c7b695a 100644
--- a/gen/sources.mk
+++ b/gen/sources.mk
@@ -676,7 +676,11 @@
   crypto/spake2plus/internal.h \
   crypto/trust_token/internal.h \
   crypto/x509/internal.h \
+  gen/boringssl_prefix_symbols_internal_x86_64_win_asm.inc \
+  gen/boringssl_prefix_symbols_internal_x86_win_asm.inc \
   include/openssl/prefix_symbols.h \
+  include/openssl/prefix_symbols_internal_S.h \
+  include/openssl/prefix_symbols_internal_c.h \
   third_party/fiat/bedrock_unverified_bareminimum.c.inc \
   third_party/fiat/bedrock_unverified_platform.c.inc \
   third_party/fiat/curve25519_32.h \
diff --git a/gen/test_support/trampoline-x86-win.asm b/gen/test_support/trampoline-x86-win.asm
index 3ef9917..3c914fa 100644
--- a/gen/test_support/trampoline-x86-win.asm
+++ b/gen/test_support/trampoline-x86-win.asm
@@ -2,7 +2,7 @@
 ; source tree. Do not edit by hand.
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_win_asm.inc"
 %endif
 %ifidn __OUTPUT_FORMAT__, win32
 %ifidn __OUTPUT_FORMAT__,obj
diff --git a/gen/test_support/trampoline-x86_64-win.asm b/gen/test_support/trampoline-x86_64-win.asm
index 7c7d3c3..a43d0ad 100644
--- a/gen/test_support/trampoline-x86_64-win.asm
+++ b/gen/test_support/trampoline-x86_64-win.asm
@@ -9,7 +9,7 @@
 %define _CET_ENDBR
 
 %ifdef BORINGSSL_PREFIX
-%include "boringssl_prefix_symbols_nasm.inc"
+%include "../boringssl_prefix_symbols_internal_x86_64_win_asm.inc"
 %endif
 section	.text code align=64
 
diff --git a/include/openssl/asm_base.h b/include/openssl/asm_base.h
index 941b482..d985d32 100644
--- a/include/openssl/asm_base.h
+++ b/include/openssl/asm_base.h
@@ -40,7 +40,7 @@
 #if defined(__ASSEMBLER__)
 
 #if defined(BORINGSSL_PREFIX)
-#include <boringssl_prefix_symbols_asm.h>
+#include <openssl/prefix_symbols_internal_S.h>
 #endif
 
 #if defined(__ELF__)
diff --git a/gen/boringssl_prefix_symbols_internal_S.inc b/include/openssl/prefix_symbols_internal_S.h
similarity index 98%
rename from gen/boringssl_prefix_symbols_internal_S.inc
rename to include/openssl/prefix_symbols_internal_S.h
index 0e1fc7e..f0d8142 100644
--- a/gen/boringssl_prefix_symbols_internal_S.inc
+++ b/include/openssl/prefix_symbols_internal_S.h
@@ -14,6 +14,12 @@
 
 // Generated by go ./util/pregenerate. Do not edit manually.
 
+#ifndef OPENSSL_HEADER_PREFIX_SYMBOLS_INTERNAL_S_H
+#define OPENSSL_HEADER_PREFIX_SYMBOLS_INTERNAL_S_H
+
+#include <openssl/prefix_symbols.h>
+
+
 #if defined(__APPLE__)
 
 #define _BORINGSSL_function_hit BORINGSSL_SYMBOL(BORINGSSL_ADD_PREFIX(BORINGSSL_function_hit))
@@ -615,3 +621,5 @@
 #define x25519_NEON BORINGSSL_ADD_PREFIX(x25519_NEON)
 
 #endif  // __APPLE__
+
+#endif  // OPENSSL_HEADER_PREFIX_SYMBOLS_INTERNAL_S_H
diff --git a/gen/boringssl_prefix_symbols_internal_c.inc b/include/openssl/prefix_symbols_internal_c.h
similarity index 98%
rename from gen/boringssl_prefix_symbols_internal_c.inc
rename to include/openssl/prefix_symbols_internal_c.h
index 0066d9b..2332027 100644
--- a/gen/boringssl_prefix_symbols_internal_c.inc
+++ b/include/openssl/prefix_symbols_internal_c.h
@@ -14,6 +14,12 @@
 
 // Generated by go ./util/pregenerate. Do not edit manually.
 
+#ifndef OPENSSL_HEADER_PREFIX_SYMBOLS_INTERNAL_C_H
+#define OPENSSL_HEADER_PREFIX_SYMBOLS_INTERNAL_C_H
+
+#include <openssl/prefix_symbols.h>
+
+
 #define BORINGSSL_function_hit BORINGSSL_ADD_PREFIX(BORINGSSL_function_hit)
 #define CRYPTO_rdrand BORINGSSL_ADD_PREFIX(CRYPTO_rdrand)
 #define CRYPTO_rdrand_multiple8_buf BORINGSSL_ADD_PREFIX(CRYPTO_rdrand_multiple8_buf)
@@ -311,3 +317,5 @@
 #define vpaes_set_decrypt_key BORINGSSL_ADD_PREFIX(vpaes_set_decrypt_key)
 #define vpaes_set_encrypt_key BORINGSSL_ADD_PREFIX(vpaes_set_encrypt_key)
 #define x25519_NEON BORINGSSL_ADD_PREFIX(x25519_NEON)
+
+#endif  // OPENSSL_HEADER_PREFIX_SYMBOLS_INTERNAL_C_H
diff --git a/rust/bssl-sys/CMakeLists.txt b/rust/bssl-sys/CMakeLists.txt
index 4bc2a3f..ae3e817 100644
--- a/rust/bssl-sys/CMakeLists.txt
+++ b/rust/bssl-sys/CMakeLists.txt
@@ -51,7 +51,7 @@
           # https://doc.rust-lang.org/nightly/rustc/platform-support.html
           --target=${RUST_BINDINGS}
   COMMAND_EXPAND_LISTS
-  DEPENDS wrapper.h boringssl_prefix_symbols
+  DEPENDS wrapper.h
   DEPFILE ${CMAKE_CURRENT_BINARY_DIR}/${wrapper_rs}.d
   WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
 )
diff --git a/util/make_prefix_headers.go b/util/make_prefix_headers.go
deleted file mode 100644
index 8e1e05c..0000000
--- a/util/make_prefix_headers.go
+++ /dev/null
@@ -1,228 +0,0 @@
-// Copyright 2018 The BoringSSL Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-//go:build ignore
-
-// This program takes a file containing newline-separated symbols, and generates
-// boringssl_prefix_symbols.h, boringssl_prefix_symbols_asm.h, and
-// boringssl_prefix_symbols_nasm.inc. These header files can be used to build
-// BoringSSL with a prefix for all symbols in order to avoid symbol name
-// conflicts when linking a project with multiple copies of BoringSSL; see
-// BUILDING.md for more details.
-package main
-
-// TODO(joshlf): For platforms which support it, use '#pragma redefine_extname'
-// instead of a custom macro. This avoids the need for a custom macro, but also
-// ensures that our renaming won't conflict with symbols defined and used by our
-// consumers (the "HMAC" problem). An example of this approach can be seen in
-// IllumOS' fork of OpenSSL:
-// https://github.com/joyent/illumos-extra/blob/master/openssl1x/sunw_prefix.h
-
-import (
-	"bufio"
-	"flag"
-	"fmt"
-	"os"
-	"path/filepath"
-	"strings"
-)
-
-var out = flag.String("out", ".", "Path to a directory where the outputs will be written")
-
-// Read newline-separated symbols from a file, ignoring any comments started
-// with '#'.
-func readSymbols(path string) ([]string, error) {
-	f, err := os.Open(path)
-	if err != nil {
-		return nil, err
-	}
-	defer f.Close()
-	scanner := bufio.NewScanner(f)
-	var ret []string
-	for scanner.Scan() {
-		line := scanner.Text()
-		if idx := strings.IndexByte(line, '#'); idx >= 0 {
-			line = line[:idx]
-		}
-		line = strings.TrimSpace(line)
-		if len(line) == 0 {
-			continue
-		}
-		ret = append(ret, line)
-	}
-	if err := scanner.Err(); err != nil {
-		return nil, err
-	}
-	return ret, nil
-}
-
-func writeCHeader(symbols []string, path string) error {
-	f, err := os.Create(path)
-	if err != nil {
-		return err
-	}
-	defer f.Close()
-
-	if _, err := f.WriteString(`// Copyright 2018 The BoringSSL Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-// BORINGSSL_ADD_PREFIX pastes two identifiers into one. It performs one
-// iteration of macro expansion on its arguments before pasting.
-#define BORINGSSL_ADD_PREFIX(a, b) BORINGSSL_ADD_PREFIX_INNER(a, b)
-#define BORINGSSL_ADD_PREFIX_INNER(a, b) a ## _ ## b
-
-`); err != nil {
-		return err
-	}
-
-	for _, symbol := range symbols {
-		if _, err := fmt.Fprintf(f, "#define %s BORINGSSL_ADD_PREFIX(BORINGSSL_PREFIX, %s)\n", symbol, symbol); err != nil {
-			return err
-		}
-	}
-
-	return nil
-}
-
-func writeASMHeader(symbols []string, path string) error {
-	f, err := os.Create(path)
-	if err != nil {
-		return err
-	}
-	defer f.Close()
-
-	if _, err := f.WriteString(`// Copyright 2018 The BoringSSL Authors
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-//     https://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-#if !defined(__APPLE__)
-#include <boringssl_prefix_symbols.h>
-#else
-// On iOS and macOS, we need to treat assembly symbols differently from other
-// symbols. The linker expects symbols to be prefixed with an underscore.
-// Perlasm thus generates symbol with this underscore applied. Our macros must,
-// in turn, incorporate it.
-#define BORINGSSL_ADD_PREFIX_MAC_ASM(a, b) BORINGSSL_ADD_PREFIX_INNER_MAC_ASM(a, b)
-#define BORINGSSL_ADD_PREFIX_INNER_MAC_ASM(a, b) _ ## a ## _ ## b
-
-`); err != nil {
-		return err
-	}
-
-	for _, symbol := range symbols {
-		if _, err := fmt.Fprintf(f, "#define _%s BORINGSSL_ADD_PREFIX_MAC_ASM(BORINGSSL_PREFIX, %s)\n", symbol, symbol); err != nil {
-			return err
-		}
-	}
-
-	_, err = fmt.Fprintf(f, "#endif\n")
-	return nil
-}
-
-func writeNASMHeader(symbols []string, path string) error {
-	f, err := os.Create(path)
-	if err != nil {
-		return err
-	}
-	defer f.Close()
-
-	// NASM uses a different syntax from the C preprocessor.
-	if _, err := f.WriteString(`; Copyright 2018 The BoringSSL Authors
-;
-; Licensed under the Apache License, Version 2.0 (the "License");
-; you may not use this file except in compliance with the License.
-; You may obtain a copy of the License at
-;
-;     https://www.apache.org/licenses/LICENSE-2.0
-;
-; Unless required by applicable law or agreed to in writing, software
-; distributed under the License is distributed on an "AS IS" BASIS,
-; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-; See the License for the specific language governing permissions and
-; limitations under the License.
-
-; 32-bit Windows adds underscores to C functions, while 64-bit Windows does not.
-%ifidn __OUTPUT_FORMAT__, win32
-`); err != nil {
-		return err
-	}
-
-	for _, symbol := range symbols {
-		if _, err := fmt.Fprintf(f, "%%xdefine _%s _ %%+ BORINGSSL_PREFIX %%+ _%s\n", symbol, symbol); err != nil {
-			return err
-		}
-	}
-
-	if _, err := fmt.Fprintf(f, "%%else\n"); err != nil {
-		return err
-	}
-
-	for _, symbol := range symbols {
-		if _, err := fmt.Fprintf(f, "%%xdefine %s BORINGSSL_PREFIX %%+ _%s\n", symbol, symbol); err != nil {
-			return err
-		}
-	}
-
-	if _, err := fmt.Fprintf(f, "%%endif\n"); err != nil {
-		return err
-	}
-
-	return nil
-}
-
-func main() {
-	flag.Parse()
-	if flag.NArg() != 1 {
-		fmt.Fprintf(os.Stderr, "Usage: %s [-out OUT] SYMBOLS\n", os.Args[0])
-		os.Exit(1)
-	}
-
-	symbols, err := readSymbols(flag.Arg(0))
-	if err != nil {
-		fmt.Fprintf(os.Stderr, "Error reading symbols: %s\n", err)
-		os.Exit(1)
-	}
-
-	if err := writeASMHeader(symbols, filepath.Join(*out, "boringssl_prefix_symbols_asm.h")); err != nil {
-		fmt.Fprintf(os.Stderr, "Error writing boringssl_prefix_symbols_asm.h: %s\n", err)
-		os.Exit(1)
-	}
-
-	if err := writeNASMHeader(symbols, filepath.Join(*out, "boringssl_prefix_symbols_nasm.inc")); err != nil {
-		fmt.Fprintf(os.Stderr, "Error writing boringssl_prefix_symbols_nasm.inc: %s\n", err)
-		os.Exit(1)
-	}
-
-}
diff --git a/util/pregenerate/asm_globals.go b/util/pregenerate/asm_globals.go
index ff648d4..123a59e 100644
--- a/util/pregenerate/asm_globals.go
+++ b/util/pregenerate/asm_globals.go
@@ -75,24 +75,41 @@
 	return ret, nil
 }
 
-// BuildAsmGlobalsCInclude builds a symbol prefixing include for C.
-func BuildAsmGlobalsCInclude(syms []string) []byte {
+// BuildAsmGlobalsCHeader builds a symbol prefixing include for C.
+func BuildAsmGlobalsCHeader(syms []string) []byte {
 	var output bytes.Buffer
 	writeHeader(&output, "//")
-	output.WriteString("\n")
+	output.WriteString(`
+#ifndef OPENSSL_HEADER_PREFIX_SYMBOLS_INTERNAL_C_H
+#define OPENSSL_HEADER_PREFIX_SYMBOLS_INTERNAL_C_H
+
+#include <openssl/prefix_symbols.h>
+
+
+`)
 	// Not using redefine_extname here, as some asm symbols are conditionally inline functions
 	// (on platforms with no asm implementation).
 	for _, sym := range syms {
 		fmt.Fprintf(&output, "#define %s BORINGSSL_ADD_PREFIX(%s)\n", sym, sym)
 	}
+	output.WriteString(`
+#endif  // OPENSSL_HEADER_PREFIX_SYMBOLS_INTERNAL_C_H
+`)
 	return output.Bytes()
 }
 
-// BuildAsmGlobalsGasInclude builds a symbol prefixing include for the GNU Assembler (gas).
-func BuildAsmGlobalsGasInclude(syms []string) []byte {
+// BuildAsmGlobalsGasHeader builds a symbol prefixing include for the GNU Assembler (gas).
+func BuildAsmGlobalsGasHeader(syms []string) []byte {
 	var output bytes.Buffer
 	writeHeader(&output, "//")
-	output.WriteString("\n")
+	output.WriteString(`
+#ifndef OPENSSL_HEADER_PREFIX_SYMBOLS_INTERNAL_S_H
+#define OPENSSL_HEADER_PREFIX_SYMBOLS_INTERNAL_S_H
+
+#include <openssl/prefix_symbols.h>
+
+
+`)
 	fmt.Fprintf(&output, "#if defined(__APPLE__)\n")
 	output.WriteString("\n")
 	for _, sym := range syms {
@@ -106,27 +123,46 @@
 	}
 	output.WriteString("\n")
 	fmt.Fprintf(&output, "#endif  // __APPLE__\n")
+	output.WriteString(`
+#endif  // OPENSSL_HEADER_PREFIX_SYMBOLS_INTERNAL_S_H
+`)
 	return output.Bytes()
 }
 
-// BuildAsmGlobalsNasmX86Include builds a symbol prefixing include for the Netwide Assembler (nasm).
-func BuildAsmGlobalsNasmX86Include(syms []string) []byte {
+// BuildAsmGlobalsNasmX86Header builds a symbol prefixing include for the Netwide Assembler (nasm).
+func BuildAsmGlobalsNasmX86Header(syms []string) []byte {
 	var output bytes.Buffer
 	writeHeader(&output, ";")
-	output.WriteString("\n")
+	output.WriteString(`
+%ifndef OPENSSL_HEADER_GEN_BORINGSSL_PREFIX_SYMBOLS_INTERNAL_X86_WIN_ASM_H
+%define OPENSSL_HEADER_GEN_BORINGSSL_PREFIX_SYMBOLS_INTERNAL_X86_WIN_ASM_H
+
+
+`)
 	for _, sym := range syms {
 		fmt.Fprintf(&output, "%%define _%s _ %%+ BORINGSSL_PREFIX %%+ _%s\n", sym, sym)
 	}
+	output.WriteString(`
+%endif  ; OPENSSL_HEADER_GEN_BORINGSSL_PREFIX_SYMBOLS_INTERNAL_X86_WIN_ASM_H
+`)
 	return output.Bytes()
 }
 
-// BuildAsmGlobalsNasmInclude builds a symbol prefixing include for the Netwide Assembler (nasm).
-func BuildAsmGlobalsNasmX8664Include(syms []string) []byte {
+// BuildAsmGlobalsNasmHeader builds a symbol prefixing include for the Netwide Assembler (nasm).
+func BuildAsmGlobalsNasmX8664Header(syms []string) []byte {
 	var output bytes.Buffer
 	writeHeader(&output, ";")
-	output.WriteString("\n")
+	output.WriteString(`
+%ifndef OPENSSL_HEADER_GEN_BORINGSSL_PREFIX_SYMBOLS_INTERNAL_X86_64_WIN_ASM_H
+%define OPENSSL_HEADER_GEN_BORINGSSL_PREFIX_SYMBOLS_INTERNAL_X86_64_WIN_ASM_H
+
+
+`)
 	for _, sym := range syms {
 		fmt.Fprintf(&output, "%%define %s BORINGSSL_PREFIX %%+ _%s\n", sym, sym)
 	}
+	output.WriteString(`
+%endif  ; OPENSSL_HEADER_GEN_BORINGSSL_PREFIX_SYMBOLS_INTERNAL_X86_64_WIN_ASM_H
+`)
 	return output.Bytes()
 }
diff --git a/util/pregenerate/build.go b/util/pregenerate/build.go
index fd829b6..4849273 100644
--- a/util/pregenerate/build.go
+++ b/util/pregenerate/build.go
@@ -339,29 +339,33 @@
 
 // Construct a task to collect assembly global symbols into the file "gen/asm.syms".
 // This task should only run after all the `PerlAsmTask`s in `perlAsmTasks` complete.
-func MakeCollectAsmGlobalTasks(perlAsmTasks []*Task, allAsmSrcs []string) []*Task {
+func MakeCollectAsmGlobalTasks(perlAsmTasks []*Task, allAsmSrcs []string, targetsOut map[string]build.Target) []*Task {
 	var syms []string
 	var err error
-	buildIncludesOnce := func() {
+	buildHeadersOnce := func() {
 		syms, err = CollectAsmGlobals(allAsmSrcs)
 	}
 	var once sync.Once
+	addGeneratedHeader(targetsOut, "include/openssl/prefix_symbols_internal_c.h")
+	addGeneratedHeader(targetsOut, "include/openssl/prefix_symbols_internal_S.h")
+	addGeneratedHeader(targetsOut, "gen/boringssl_prefix_symbols_internal_x86_win_asm.inc")
+	addGeneratedHeader(targetsOut, "gen/boringssl_prefix_symbols_internal_x86_64_win_asm.inc")
 	return []*Task{
-		NewSimpleTask("gen/boringssl_prefix_symbols_internal_c.inc", func() ([]byte, error) {
-			once.Do(buildIncludesOnce)
-			return BuildAsmGlobalsCInclude(syms), err
+		NewSimpleTask("include/openssl/prefix_symbols_internal_c.h", func() ([]byte, error) {
+			once.Do(buildHeadersOnce)
+			return BuildAsmGlobalsCHeader(syms), err
 		}, perlAsmTasks...),
-		NewSimpleTask("gen/boringssl_prefix_symbols_internal_S.inc", func() ([]byte, error) {
-			once.Do(buildIncludesOnce)
-			return BuildAsmGlobalsGasInclude(syms), err
+		NewSimpleTask("include/openssl/prefix_symbols_internal_S.h", func() ([]byte, error) {
+			once.Do(buildHeadersOnce)
+			return BuildAsmGlobalsGasHeader(syms), err
 		}, perlAsmTasks...),
-		NewSimpleTask("gen/boringssl_prefix_symbols_internal_x86_asm.inc", func() ([]byte, error) {
-			once.Do(buildIncludesOnce)
-			return BuildAsmGlobalsNasmX86Include(syms), err
+		NewSimpleTask("gen/boringssl_prefix_symbols_internal_x86_win_asm.inc", func() ([]byte, error) {
+			once.Do(buildHeadersOnce)
+			return BuildAsmGlobalsNasmX86Header(syms), err
 		}, perlAsmTasks...),
-		NewSimpleTask("gen/boringssl_prefix_symbols_internal_x86_64_asm.inc", func() ([]byte, error) {
-			once.Do(buildIncludesOnce)
-			return BuildAsmGlobalsNasmX8664Include(syms), err
+		NewSimpleTask("gen/boringssl_prefix_symbols_internal_x86_64_win_asm.inc", func() ([]byte, error) {
+			once.Do(buildHeadersOnce)
+			return BuildAsmGlobalsNasmX8664Header(syms), err
 		}, perlAsmTasks...),
 	}
 }
diff --git a/util/pregenerate/pregenerate.go b/util/pregenerate/pregenerate.go
index 969426a..483e9c7 100644
--- a/util/pregenerate/pregenerate.go
+++ b/util/pregenerate/pregenerate.go
@@ -179,8 +179,8 @@
 	}
 
 	tasks = append(tasks, MakePrefixingIncludes(targetsIn, targetsOut)...)
+	tasks = append(tasks, MakeCollectAsmGlobalTasks(perlAsmTasks, allAsmSrcs, targetsOut)...)
 	tasks = append(tasks, MakeBuildFiles(targetsOut)...)
-	tasks = append(tasks, MakeCollectAsmGlobalTasks(perlAsmTasks, allAsmSrcs)...)
 	tasks = append(tasks, NewSimpleTask("gen/README.md", func() ([]byte, error) {
 		return []byte(readme), nil
 	}))