From 5ceed9216e7ad9d101579338f7841474f3bb9e41 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Fri, 1 Nov 2019 13:01:14 -0700 Subject: [PATCH 1/2] Force `patchelf` to use 64KB page size on aarch64/powerpc64le This fixes problems with binaries on these two platforms that often use these large page sizes. --- Make.inc | 14 ++++++++++++++ Makefile | 10 +++++----- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Make.inc b/Make.inc index cac4fb1a8c08d..b7df892369c33 100644 --- a/Make.inc +++ b/Make.inc @@ -928,6 +928,20 @@ else PCRE_CONFIG := $(build_depsbindir)/pcre2-config endif +ifeq ($(USE_SYSTEM_PATCHELF), 1) +PATCHELF := patchelf +else +PATCHELF := $(build_depsbindir)/patchelf +endif + +# On aarch64 and powerpc64le, we assume the page size is 64K. Our binutils linkers +# and such already assume this, but `patchelf` seems to be behind the times. We +# explicitly tell it to use this large page size so that when we rewrite rpaths and +# such, we don't accidentally create incorrectly-aligned sections in our ELF files. +ifneq (,$(filter $(ARCH),aarch64 powerpc64le)) +PATCHELF += --page-size=65536 +endif + # Use ILP64 BLAS interface when building openblas from source on 64-bit architectures ifeq ($(BINARY), 64) ifeq ($(USE_SYSTEM_BLAS), 1) diff --git a/Makefile b/Makefile index 07b6c9a5df177..3fcc7fbaa9c43 100644 --- a/Makefile +++ b/Makefile @@ -392,7 +392,7 @@ ifneq ($(DARWIN_FRAMEWORK),1) endif else ifneq (,$(findstring $(OS),Linux FreeBSD)) for j in $(JL_TARGETS) ; do \ - patchelf --set-rpath '$$ORIGIN/$(private_libdir_rel):$$ORIGIN/$(libdir_rel)' $(DESTDIR)$(bindir)/$$j; \ + $(PATCHELF) --set-rpath '$$ORIGIN/$(private_libdir_rel):$$ORIGIN/$(libdir_rel)' $(DESTDIR)$(bindir)/$$j; \ done endif @@ -412,15 +412,15 @@ endif endif # On FreeBSD, remove the build's libdir from each library's RPATH ifeq ($(OS),FreeBSD) - $(JULIAHOME)/contrib/fixup-rpath.sh $(build_depsbindir)/patchelf $(DESTDIR)$(libdir) $(build_libdir) - $(JULIAHOME)/contrib/fixup-rpath.sh $(build_depsbindir)/patchelf $(DESTDIR)$(private_libdir) $(build_libdir) - $(JULIAHOME)/contrib/fixup-rpath.sh $(build_depsbindir)/patchelf $(DESTDIR)$(bindir) $(build_libdir) + $(JULIAHOME)/contrib/fixup-rpath.sh "$(PATCHELF)" $(DESTDIR)$(libdir) $(build_libdir) + $(JULIAHOME)/contrib/fixup-rpath.sh "$(PATCHELF)" $(DESTDIR)$(private_libdir) $(build_libdir) + $(JULIAHOME)/contrib/fixup-rpath.sh "$(PATCHELF)" $(DESTDIR)$(bindir) $(build_libdir) # Set libgfortran's RPATH to ORIGIN instead of GCCPATH. It's only libgfortran that # needs to be fixed here, as libgcc_s and libquadmath don't have RPATHs set. If we # don't set libgfortran's RPATH, it won't be able to find its friends on systems # that don't have the exact GCC port installed used for the build. for lib in $(DESTDIR)$(private_libdir)/libgfortran*$(SHLIB_EXT)*; do \ - $(build_depsbindir)/patchelf --set-rpath '$$ORIGIN' $$lib; \ + $(PATCHELF) --set-rpath '$$ORIGIN' $$lib; \ done endif From ffb3ed0e746b82b9aa62654680646ae5c6506829 Mon Sep 17 00:00:00 2001 From: Elliot Saba Date: Fri, 1 Nov 2019 18:02:09 -0700 Subject: [PATCH 2/2] Force `PATCHELF` override on `fixup-libgfortran.sh` as well --- Makefile | 2 +- contrib/fixup-libgfortran.sh | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3fcc7fbaa9c43..03a7622a2734b 100644 --- a/Makefile +++ b/Makefile @@ -269,7 +269,7 @@ endef ifeq (,$(findstring $(OS),FreeBSD WINNT)) julia-base: $(build_libdir)/libgfortran*.$(SHLIB_EXT)* $(build_libdir)/libgfortran*.$(SHLIB_EXT)*: | $(build_libdir) julia-deps - -$(CUSTOM_LD_LIBRARY_PATH) PATH="$(PATH):$(build_depsbindir)" $(JULIAHOME)/contrib/fixup-libgfortran.sh --verbose $(build_libdir) + -$(CUSTOM_LD_LIBRARY_PATH) PATH="$(PATH):$(build_depsbindir)" PATCHELF="$(PATCHELF)" $(JULIAHOME)/contrib/fixup-libgfortran.sh --verbose $(build_libdir) JL_PRIVATE_LIBS-0 += libgfortran libgcc_s libquadmath endif diff --git a/contrib/fixup-libgfortran.sh b/contrib/fixup-libgfortran.sh index fbe744bff65c7..d1f00bdf85950 100755 --- a/contrib/fixup-libgfortran.sh +++ b/contrib/fixup-libgfortran.sh @@ -3,6 +3,7 @@ # Run as: fixup-libgfortran.sh [--verbose] <$private_libdir> FC=${FC:-gfortran} +PATCHELF=${PATCHELF:-patchelf} # If we're invoked with "--verbose", create a `debug` function that prints stuff out if [ "$1" = "--verbose" ] || [ "$1" = "-v" ]; then @@ -126,7 +127,7 @@ change_linkage() echo " $old_link" install_name_tool -change "$old_link" "@rpath/$soname" "$lib_path" else # $UNAME is "Linux", we only have two options, see above - patchelf --set-rpath \$ORIGIN "$lib_path" + ${PATCHELF} --set-rpath \$ORIGIN "$lib_path" fi }