Make deps: Compile own version of nasm for Apple
The upstream version of nasm does not put version information to the generated object files, which makes linker to show the following warning: building for macOS, but linking in object file Using own patched version of nasm which puts required information to the object file, making linker happy. The plan is to either streamline the patch and provide it to the upstream, or, it that takes too long, get an independent fix from the upstream.
This commit is contained in:
parent
202e7ccaae
commit
1e3c0b4b03
@ -76,6 +76,7 @@ include(cmake/llvm.cmake)
|
||||
include(cmake/clang.cmake)
|
||||
if(APPLE)
|
||||
include(cmake/openmp.cmake)
|
||||
include(cmake/nasm.cmake)
|
||||
endif()
|
||||
include(cmake/openimageio.cmake)
|
||||
include(cmake/tiff.cmake)
|
||||
|
@ -143,6 +143,12 @@ if(WIN32)
|
||||
external_zlib_mingw
|
||||
)
|
||||
endif()
|
||||
if(APPLE)
|
||||
add_dependencies(
|
||||
external_ffmpeg
|
||||
external_nasm
|
||||
)
|
||||
endif()
|
||||
|
||||
if(BUILD_MODE STREQUAL Release AND WIN32)
|
||||
ExternalProject_Add_Step(external_ffmpeg after_install
|
||||
|
29
build_files/build_environment/cmake/nasm.cmake
Normal file
29
build_files/build_environment/cmake/nasm.cmake
Normal file
@ -0,0 +1,29 @@
|
||||
# ***** BEGIN GPL LICENSE BLOCK *****
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or
|
||||
# modify it under the terms of the GNU General Public License
|
||||
# as published by the Free Software Foundation; either version 2
|
||||
# of the License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software Foundation,
|
||||
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
#
|
||||
# ***** END GPL LICENSE BLOCK *****
|
||||
|
||||
ExternalProject_Add(external_nasm
|
||||
URL ${NASM_URI}
|
||||
DOWNLOAD_DIR ${DOWNLOAD_DIR}
|
||||
URL_HASH SHA256=${NASM_HASH}
|
||||
PREFIX ${BUILD_DIR}/nasm
|
||||
PATCH_COMMAND ${PATCH_CMD} --verbose -p 1 -N -d ${BUILD_DIR}/nasm/src/external_nasm < ${PATCH_DIR}/nasm.diff
|
||||
CONFIGURE_COMMAND ${CONFIGURE_ENV} && cd ${BUILD_DIR}/nasm/src/external_nasm/ && ${CONFIGURE_COMMAND} --prefix=${LIBDIR}/nasm
|
||||
BUILD_COMMAND ${CONFIGURE_ENV} && cd ${BUILD_DIR}/nasm/src/external_nasm/ && make -j${MAKE_THREADS}
|
||||
INSTALL_COMMAND ${CONFIGURE_ENV} && cd ${BUILD_DIR}/nasm/src/external_nasm/ && make install
|
||||
INSTALL_DIR ${LIBDIR}/nasm
|
||||
)
|
@ -305,6 +305,10 @@ set(MESA_VERSION 18.3.1)
|
||||
set(MESA_URI ftp://ftp.freedesktop.org/pub/mesa//mesa-${MESA_VERSION}.tar.xz)
|
||||
set(MESA_HASH d60828056d77bfdbae0970f9b15fb1be)
|
||||
|
||||
set(NASM_VERSION 2.15.02)
|
||||
set(NASM_URI https://www.nasm.us/pub/nasm/releasebuilds/${NASM_VERSION}/nasm-${NASM_VERSION}.tar.xz)
|
||||
set(NASM_HASH f4fd1329b1713e1ccd34b2fc121c4bcd278c9f91cc4cb205ae8fcd2e4728dd14)
|
||||
|
||||
set(XR_OPENXR_SDK_VERSION 1.0.8)
|
||||
set(XR_OPENXR_SDK_URI https://github.com/KhronosGroup/OpenXR-SDK/archive/release-${XR_OPENXR_SDK_VERSION}.tar.gz)
|
||||
set(XR_OPENXR_SDK_HASH c6de63d2e0f9029aa58dfa97cad8ce07)
|
||||
|
@ -39,3 +39,10 @@ ExternalProject_Add(external_x264
|
||||
if(MSVC)
|
||||
set_target_properties(external_x264 PROPERTIES FOLDER Mingw)
|
||||
endif()
|
||||
|
||||
if(APPLE)
|
||||
add_dependencies(
|
||||
external_x264
|
||||
external_nasm
|
||||
)
|
||||
endif()
|
||||
|
129
build_files/build_environment/patches/nasm.diff
Normal file
129
build_files/build_environment/patches/nasm.diff
Normal file
@ -0,0 +1,129 @@
|
||||
diff --git a/output/macho.h b/output/macho.h
|
||||
index 538c531e..fd5e8849 100644
|
||||
--- a/output/macho.h
|
||||
+++ b/output/macho.h
|
||||
@@ -60,6 +60,8 @@
|
||||
#define LC_SEGMENT 0x1
|
||||
#define LC_SEGMENT_64 0x19
|
||||
#define LC_SYMTAB 0x2
|
||||
+#define LC_VERSION_MIN_MACOSX 0x24
|
||||
+#define LC_BUILD_VERSION 0x32
|
||||
|
||||
/* Symbol type bits */
|
||||
#define N_STAB 0xe0
|
||||
diff --git a/output/outmacho.c b/output/outmacho.c
|
||||
index 08147883..de6ec902 100644
|
||||
--- a/output/outmacho.c
|
||||
+++ b/output/outmacho.c
|
||||
@@ -38,6 +38,8 @@
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
+#include <stdlib.h>
|
||||
+
|
||||
#include "nctype.h"
|
||||
|
||||
#include "nasm.h"
|
||||
@@ -64,6 +66,8 @@
|
||||
#define MACHO_SYMCMD_SIZE 24
|
||||
#define MACHO_NLIST_SIZE 12
|
||||
#define MACHO_RELINFO_SIZE 8
|
||||
+#define MACHO_BUILD_VERSION_SIZE 24
|
||||
+#define MACHO_VERSION_MIN_MACOSX_SIZE 16
|
||||
|
||||
#define MACHO_HEADER64_SIZE 32
|
||||
#define MACHO_SEGCMD64_SIZE 72
|
||||
@@ -1224,6 +1228,46 @@ static void macho_layout_symbols (uint32_t *numsyms,
|
||||
}
|
||||
}
|
||||
|
||||
+static bool get_full_version_from_env (const char *variable_name,
|
||||
+ int *r_major,
|
||||
+ int *r_minor,
|
||||
+ int *r_patch) {
|
||||
+ *r_major = 0;
|
||||
+ *r_minor = 0;
|
||||
+ *r_patch = 0;
|
||||
+
|
||||
+ const char *value = getenv(variable_name);
|
||||
+ if (value == NULL || value[0] == '\0') {
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
+ const char *current_value = value;
|
||||
+ const char *end_value = value + strlen(value);
|
||||
+
|
||||
+ char *endptr;
|
||||
+
|
||||
+ *r_major = strtol(current_value, &endptr, 10);
|
||||
+ if (endptr >= end_value) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ current_value = endptr + 1;
|
||||
+
|
||||
+ *r_minor = strtol(current_value, &endptr, 10);
|
||||
+ if (endptr >= end_value) {
|
||||
+ return true;
|
||||
+ }
|
||||
+ current_value = endptr + 1;
|
||||
+
|
||||
+ *r_patch = strtol(current_value, &endptr, 10);
|
||||
+
|
||||
+ return true;
|
||||
+}
|
||||
+
|
||||
+static bool need_version_min_macosx_command (void) {
|
||||
+ return getenv("MACOSX_DEPLOYMENT_TARGET") &&
|
||||
+ getenv("MACOSX_SDK_VERSION");
|
||||
+}
|
||||
+
|
||||
/* Calculate some values we'll need for writing later. */
|
||||
|
||||
static void macho_calculate_sizes (void)
|
||||
@@ -1270,6 +1314,12 @@ static void macho_calculate_sizes (void)
|
||||
head_sizeofcmds += fmt.segcmd_size + seg_nsects * fmt.sectcmd_size;
|
||||
}
|
||||
|
||||
+ /* LC_VERSION_MIN_MACOSX */
|
||||
+ if (need_version_min_macosx_command()) {
|
||||
+ ++head_ncmds;
|
||||
+ head_sizeofcmds += MACHO_VERSION_MIN_MACOSX_SIZE;
|
||||
+ }
|
||||
+
|
||||
if (nsyms > 0) {
|
||||
++head_ncmds;
|
||||
head_sizeofcmds += MACHO_SYMCMD_SIZE;
|
||||
@@ -1653,6 +1703,33 @@ static void macho_write (void)
|
||||
else
|
||||
nasm_warn(WARN_OTHER, "no sections?");
|
||||
|
||||
+#define ENCODE_BUILD_VERSION(major, minor, patch) \
|
||||
+ (((major) << 16) | ((minor) << 8) | (patch))
|
||||
+
|
||||
+ if (0) {
|
||||
+ fwriteint32_t(LC_BUILD_VERSION, ofile); /* cmd == LC_BUILD_VERSION */
|
||||
+ fwriteint32_t(MACHO_BUILD_VERSION_SIZE, ofile); /* size of load command */
|
||||
+ fwriteint32_t(1, ofile); /* platform */
|
||||
+ fwriteint32_t(ENCODE_BUILD_VERSION(10, 13, 0), ofile); /* minos, X.Y.Z is encoded in nibbles xxxx.yy.zz */
|
||||
+ fwriteint32_t(ENCODE_BUILD_VERSION(10, 15, 4), ofile); /* sdk, X.Y.Z is encoded in nibbles xxxx.yy.zz */
|
||||
+ fwriteint32_t(0, ofile); /* number of tool entries following this */
|
||||
+ }
|
||||
+
|
||||
+ if (need_version_min_macosx_command()) {
|
||||
+ int sdk_major, sdk_minor, sdk_patch;
|
||||
+ get_full_version_from_env("MACOSX_SDK_VERSION", &sdk_major, &sdk_minor, &sdk_patch);
|
||||
+
|
||||
+ int version_major, version_minor, version_patch;
|
||||
+ get_full_version_from_env("MACOSX_DEPLOYMENT_TARGET", &version_major, &version_minor, &version_patch);
|
||||
+
|
||||
+ fwriteint32_t(LC_VERSION_MIN_MACOSX, ofile); /* cmd == LC_VERSION_MIN_MACOSX */
|
||||
+ fwriteint32_t(MACHO_VERSION_MIN_MACOSX_SIZE, ofile); /* size of load command */
|
||||
+ fwriteint32_t(ENCODE_BUILD_VERSION(version_major, version_minor, version_patch), ofile); /* minos, X.Y.Z is encoded in nibbles xxxx.yy.zz */
|
||||
+ fwriteint32_t(ENCODE_BUILD_VERSION(sdk_major, sdk_minor, sdk_patch), ofile); /* sdk, X.Y.Z is encoded in nibbles xxxx.yy.zz */
|
||||
+ }
|
||||
+
|
||||
+#undef ENCODE_BUILD_VERSION
|
||||
+
|
||||
if (nsyms > 0) {
|
||||
/* write out symbol command */
|
||||
fwriteint32_t(LC_SYMTAB, ofile); /* cmd == LC_SYMTAB */
|
Loading…
Reference in New Issue
Block a user