Skip to content

Commit

Permalink
Force patchelf to use 64KB page size on aarch64/powerpc64le (#33745)
Browse files Browse the repository at this point in the history
Force `patchelf` to use 64KB page size on aarch64/powerpc64le
  • Loading branch information
staticfloat authored Nov 2, 2019
2 parents 3f0e7d6 + ffb3ed0 commit c9a2553
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
14 changes: 14 additions & 0 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down
3 changes: 2 additions & 1 deletion contrib/fixup-libgfortran.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit c9a2553

Please sign in to comment.