1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-12-22 04:17:44 +00:00
freebsd-ports/java/openjdk13/Makefile
Dimitry Andric 3822416493 java/openjdk*: work around UB in markOopDesc, fix builds with clang 13
During an exp-run for llvm 13 (see bug 258209), it turned out that
java/openjdk11 through openjdk13 fail to build with clang 13:

=== Output from failing command(s) repeated here ===
* For target jdk__packages_attribute.done:

These crashes are all caused by the markOop/markOopDesc classes, which
are used to keep track of objects, and which are 'marked' using the low
few bits. (See
https://github.com/openjdk/jdk13u/blob/master/src/hotspot/share/oops/markOop.hpp
).

After some laborious bisecting, I found out that these crashes start
occuring after the upstream commit https://github.com
/llvm/llvm-project/commit/16d03818412 (Return "[CGCall] Annotate this
argument with alignment").

What happens afterwards, is that clang considers the "this" pointer to
always be aligned to the alignment of the actual object, and then
masking or adding a few low bits is not working as expected.

The reason openjdk14 and higher work fine with clang 13, and don't crash
similarly, is that the OpenJDK people completely redid the
markOop/markOopDesc classes in
ae5615c614
("8229258: Rework markOop and markOopDesc into a simpler mark word value
carrier"). E.g, the markOopDesc class was renamed to markWord, and
*stores* a pointer-like value instead of *being* a pointer-like value.
This is a much safer way of handling things.

However, this upstream commit is *very* large, as are a few of its
follow-ups, which is probably the reason why it has not been backported
to JDKs <= 13. I tried manually backporting it, but got lost in many
nasty patch conflicts and problems.

As a workaround, build openjdk8 through 13 with clang12 from the
devel/llvm12 port, for the time being.

In addition, allow openjdk14 through 17 to be built with clang 13, by
adding -Wno-unused-but-set-parameter to the compilation flags.

PR:		258954
Approved by:	maintainer timeout (2 weeks)
MFH:		2021Q4
2021-10-16 14:22:03 +02:00

189 lines
5.7 KiB
Makefile

PORTNAME= openjdk
DISTVERSIONPREFIX= jdk-
DISTVERSION= ${JDK_MAJOR_VERSION}.${JDK_MINOR_VERSION}.${JDK_PATCH_VERSION}+${JDK_BUILD_NUMBER}-${BSD_JDK_VERSION}
PORTREVISION= 1
CATEGORIES= java devel
PKGNAMESUFFIX?= ${JDK_MAJOR_VERSION}
MAINTAINER= java@FreeBSD.org
COMMENT= Java Development Kit ${JDK_MAJOR_VERSION}
LICENSE= GPLv2
ONLY_FOR_ARCHS= aarch64 amd64 i386 powerpc64 powerpc64le
BUILD_DEPENDS= zip:archivers/zip \
autoconf>0:devel/autoconf \
${LOCALBASE}/include/cups/cups.h:print/cups \
bash:shells/bash \
gsed:textproc/gsed
LIB_DEPENDS= libasound.so:audio/alsa-lib \
libfontconfig.so:x11-fonts/fontconfig \
libfreetype.so:print/freetype2 \
libgif.so:graphics/giflib \
liblcms2.so:graphics/lcms2 \
libpng.so:graphics/png
RUN_DEPENDS= javavm:java/javavmwrapper
USES= compiler:features cpe gmake iconv jpeg pkgconfig xorg
USE_XORG= x11 xext xi xrandr xrender xt xtst
CPE_VENDOR= oracle
USE_GITHUB= yes
GH_ACCOUNT= battleblow
GH_PROJECT= jdk13u
NO_CCACHE= yes
_MAKE_JOBS= #
MAKE_ENV= LANG="C" \
LC_ALL="C" \
CLASSPATH="" \
JAVA_HOME="" \
LD_LIBRARY_PATH="" \
CC=${CC} \
CXX=${CXX} \
CPP=${CPP} \
MAKEFLAGS=""
JDK_OSARCH= bsd-${ARCH:S/amd64/x86_64/:S/i386/x86/:S/powerpc64/ppc64/}
JDK_BUILDDIR= ${WRKSRC}/build/${JDK_OSARCH}-${JDK_BUILD_JVM}-${JDK_BUILD_TYPE}
JDK_IMAGEDIR= ${JDK_BUILDDIR}/images/jdk
INSTALLDIR= ${PREFIX}/${PKGBASE}
NOPRECIOUSMAKEVARS= yes
JDK_MAJOR_VERSION= 13
JDK_MINOR_VERSION= 0
JDK_PATCH_VERSION= 8
JDK_BUILD_NUMBER= 5
BSD_JDK_VERSION= 1
JDK_BUG_URL= https://bugs.freebsd.org/bugzilla/enter_bug.cgi?product=Ports%20%26%20Packages&component=Individual%20Port(s)&short_desc=java/${PORTNAME}${JDK_MAJOR_VERSION}%3A%20
GNU_CONFIGURE= yes
CONFIGURE_ENV= CC=${CC} \
CXX=${CXX} \
CPP=${CPP} \
ac_cv_path_SED=${LOCALBASE}/bin/gsed
CONFIGURE_ARGS= --with-boot-jdk=${BOOTSTRAPJDKDIR} \
--disable-ccache \
--disable-javac-server \
--disable-hotspot-gtest \
--with-alsa=${LOCALBASE} \
--with-cups=${LOCALBASE} \
--with-fontconfig=${LOCALBASE} \
--with-freetype=system \
--with-freetype-include=${LOCALBASE}/include/freetype2 \
--with-freetype-lib=${LOCALBASE}/lib \
--with-libjpeg=system \
--with-giflib=system \
--with-giflib-include=${LOCALBASE}/include \
--with-giflib-lib=${LOCALBASE}/lib \
--with-libpng=system \
--with-zlib=system \
--with-lcms=system \
--x-includes=${LOCALBASE}/include \
--x-libraries=${LOCALBASE}/lib \
--with-cacerts-file=${FILESDIR}/cacerts \
--with-version-string=${JDK_MAJOR_VERSION}.${JDK_MINOR_VERSION}.${JDK_PATCH_VERSION}+${JDK_BUILD_NUMBER}-${BSD_JDK_VERSION} \
--with-native-debug-symbols=none \
--with-debug-level=release \
--with-vendor-name="OpenJDK BSD Porting Team" \
--with-vendor-url="https://github.com/${GH_ACCOUNT}/${GH_PROJECT}/" \
--with-vendor-bug-url="${JDK_BUG_URL}" \
--with-vendor-vm-bug-url="${JDK_BUG_URL}"
JAVAVMS_COMMENT= OpenJDK${JDK_MAJOR_VERSION}
ALL_TARGET= images
JDK_BUILD_TYPE= release
.include <bsd.port.pre.mk>
BOOTSTRAP_JDKS= ${LOCALBASE}/openjdk13 \
${LOCALBASE}/openjdk12
# do we have valid native jdk installed?
.for BJDK in ${BOOTSTRAP_JDKS}
. if !defined(BOOTSTRAPJDKDIR) && exists(${BJDK}/bin/javac)
BOOTSTRAPJDKDIR= ${BJDK}
. endif
.endfor
# if no valid jdk found, set dependency
.if !defined(BOOTSTRAPJDKDIR)
BOOTSTRAPJDKDIR?= ${LOCALBASE}/openjdk12
BUILD_DEPENDS+= ${BOOTSTRAPJDKDIR}/bin/javac:java/openjdk12
.endif
JDK_BUILD_JVM= server
MAKE_ENV+= --with-toolchain-type=${COMPILER_TYPE}
CONFIGURE_ARGS+= --with-toolchain-type=${COMPILER_TYPE}
.if ${COMPILER_TYPE} == gcc
USE_GCC= yes
CONFIGURE_ARGS+= --with-extra-ldflags="-Wl,-rpath=${LOCALBASE}/lib/gcc${GCC_DEFAULT} -L/usr/local/lib/gcc${GCC_DEFAULT}" \
--with-extra-cflags="-Wl,-rpath=${LOCALBASE}/lib/gcc${GCC_DEFAULT}" \
--with-extra-cxxflags="-Wl,-rpath=${LOCALBASE}/lib/gcc${GCC_DEFAULT}"
.else
MAKE_ENV+= USE_CLANG=true
.if ${COMPILER_VERSION} >= 130
# PR258954: OpenJDK <= 13 crash due to undefined behavior with clang >= 13
# See also https://bugs.openjdk.java.net/browse/JDK-8229258
LLVM_VER= 12
BUILD_DEPENDS+= clang${LLVM_VER}:devel/llvm${LLVM_VER}
CC= ${LOCALBASE}/bin/clang${LLVM_VER}
CXX= ${LOCALBASE}/bin/clang++${LLVM_VER}
.endif
.endif
.if ${ARCH} == aarch64 || ${ARCH:Mpowerpc64*}
CONFIGURE_ARGS+= --disable-warnings-as-errors
.endif
.if ${ARCH} == aarch64 || (defined(PPC_ABI) && ${PPC_ABI} == ELFv1)
CONFIGURE_ARGS+= --disable-dtrace
.endif
.if (defined(PPC_ABI) && ${PPC_ABI} == ELFv2) || ${ARCH} == powerpc64le
CONFIGURE_ARGS+= --disable-precompiled-headers
.endif
.if ${ARCH} != amd64
CONFIGURE_ARGS+= --enable-aot=no
.endif
.if ${ARCH} == powerpc64 && ${OSREL:C/\.[0-9]//} == 12
EXTRA_PATCHES= ${PATCHDIR}/extra-patch-src_hotspot_cpu_ppc_vm__version__ppc.hpp
.endif
.if empty(ICONV_LIB)
ICONV_CFLAGS= -DLIBICONV_PLUG
.else
ICONV_CFLAGS= -I${LOCALBASE}/include
ICONV_LDFLAGS= -L${LOCALBASE}/lib
ICONV_LIBS= ${ICONV_LIB}
.endif
post-patch:
@${FIND} ${WRKSRC} -name '*.orig' -delete
@${CHMOD} 755 ${WRKSRC}/configure
@${REINPLACE_CMD} -e 's|%%LOCALBASE%%|${LOCALBASE}|' \
${WRKSRC}/configure \
${WRKSRC}/src/hotspot/os/bsd/os_bsd.cpp
@${REINPLACE_CMD} -e 's|%%ICONV_CFLAGS%%|${ICONV_CFLAGS}|' \
-e 's|%%ICONV_LDFLAGS%%|${ICONV_LDFLAGS}|' \
-e 's|%%ICONV_LIBS%%|${ICONV_LIBS}|' \
${WRKSRC}/make/autoconf/libraries.m4
do-install:
@${MKDIR} ${STAGEDIR}${INSTALLDIR}
@cd ${JDK_IMAGEDIR} && ${COPYTREE_SHARE} . ${STAGEDIR}${INSTALLDIR}
@cd ${STAGEDIR}${INSTALLDIR} && \
${FIND} bin -type f -exec ${CHMOD} ${BINMODE} {} \;
@${CHMOD} ${BINMODE} ${STAGEDIR}${INSTALLDIR}/lib/jspawnhelper
@${ECHO} "@javavm ${INSTALLDIR}/bin/java" >> ${TMPPLIST}
@${FIND} ${STAGEDIR}${INSTALLDIR} -not -type d | ${SORT} | \
${SED} -e 's|^${STAGEDIR}${PREFIX}/||' >> ${TMPPLIST}
.include <bsd.port.post.mk>