< prev index next >

make/hotspot/lib/CompileJvm.gmk

Print this page

        

@@ -1,7 +1,7 @@
 #
-# Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013, 2018, Oracle and/or its affiliates. All rights reserved.
 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 #
 # This code is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 only, as
 # published by the Free Software Foundation.  Oracle designates this

@@ -268,5 +268,42 @@
 # defined after the above call to BUILD_LIBJVM. Mapfile will be generated
 # after all object files are built, but before the jvm library is linked.
 include lib/JvmMapfile.gmk
 
 TARGETS += $(BUILD_LIBJVM)
+
+################################################################################
+# Hotspot disallows the use of global operators 'new' and 'delete'. This build
+# time check helps enforce this requirement. If you trigger this check and the
+# reference is not obvious from the source, GNU objdump can be used to help find
+# the reference:
+#
+# objdump -lrdSC <path/to/file.o>
+#
+# -C demangle
+# -d disassemble
+# -r print relocation entries, interspersed with the disassembly
+# -S print source code, intermixed with disassembly
+# -l include filenames and line numbers
+#
+# Search the output for the operator(s) of interest, to see where they are
+# referenced.
+
+ifneq ($(filter $(TOOLCHAIN_TYPE), gcc clang), )
+
+  OP_REGEXP := \*UND\*.*[^:]operator (new|delete)
+
+  define SetupOperatorNewDeleteCheck
+    $1.op_check: $1
+        if [ -n "`$(OBJDUMP) -t $$< | $(CXXFILT) | $(EGREP) '$(OP_REGEXP)'`" ]; then \
+          $(ECHO) "$$<: Error: Use of global operators new and delete is not allowed in Hotspot:"; \
+          $(OBJDUMP) -t $$< | $(CXXFILT) | $(EGREP) '$(OP_REGEXP)'; \
+          $(ECHO) "See: $(TOPDIR)/make/hotspot/lib/CompileJvm.gmk"; \
+          exit 1; \
+        fi
+        $(TOUCH) $$@
+
+    TARGETS += $1.op_check
+  endef
+
+  $(foreach o, $(BUILD_LIBJVM_ALL_OBJS), $(eval $(call SetupOperatorNewDeleteCheck,$o)))
+endif
< prev index next >