1 #
   2 # Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved.
   3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4 #
   5 # This code is free software; you can redistribute it and/or modify it
   6 # under the terms of the GNU General Public License version 2 only, as
   7 # published by the Free Software Foundation.  Oracle designates this
   8 # particular file as subject to the "Classpath" exception as provided
   9 # by Oracle in the LICENSE file that accompanied this code.
  10 #
  11 # This code is distributed in the hope that it will be useful, but WITHOUT
  12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14 # version 2 for more details (a copy is included in the LICENSE file that
  15 # accompanied this code).
  16 #
  17 # You should have received a copy of the GNU General Public License version
  18 # 2 along with this work; if not, write to the Free Software Foundation,
  19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20 #
  21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22 # or visit www.oracle.com if you need additional information or have any
  23 # questions.
  24 #
  25 
  26 $(eval $(call IncludeCustomExtension, hotspot/lib/JvmMapfile.gmk))
  27 
  28 ################################################################################
  29 # Combine a list of static symbols
  30 
  31 ifeq ($(call And, $(call isTargetOs, windows) $(call isTargetCpu, x86_64)), false)
  32   # On Windows x86_64, we should not have any symbols at all, since that
  33   # results in duplicate warnings from the linker (JDK-8043491).
  34   SYMBOLS_SRC += $(TOPDIR)/make/hotspot/symbols/symbols-shared
  35 endif
  36 
  37 ifeq ($(call isTargetOsType, unix), true)
  38   SYMBOLS_SRC += $(TOPDIR)/make/hotspot/symbols/symbols-unix
  39 endif
  40 
  41 ifneq ($(wildcard $(TOPDIR)/make/hotspot/symbols/symbols-$(OPENJDK_TARGET_OS)), )
  42   SYMBOLS_SRC += $(TOPDIR)/make/hotspot/symbols/symbols-$(OPENJDK_TARGET_OS)
  43 endif
  44 
  45 ifneq ($(findstring debug, $(DEBUG_LEVEL)), )
  46   ifneq ($(wildcard $(TOPDIR)/make/hotspot/symbols/symbols-$(OPENJDK_TARGET_OS)-debug), )
  47     SYMBOLS_SRC += $(TOPDIR)/make/hotspot/symbols/symbols-$(OPENJDK_TARGET_OS)-debug
  48   endif
  49 endif
  50 
  51 ################################################################################
  52 # Create a dynamic list of symbols from the built object files. This is highly
  53 # platform dependent.
  54 
  55 ifeq ($(call isTargetOs, linux), true)
  56   DUMP_SYMBOLS_CMD := $(NM) --defined-only *.o
  57   ifneq ($(FILTER_SYMBOLS_PATTERN), )
  58     FILTER_SYMBOLS_PATTERN := $(FILTER_SYMBOLS_PATTERN)|
  59   endif
  60   FILTER_SYMBOLS_PATTERN := $(FILTER_SYMBOLS_PATTERN)^_ZTV|^gHotSpotVM|^UseSharedSpaces$$
  61   FILTER_SYMBOLS_PATTERN := $(FILTER_SYMBOLS_PATTERN)|^_ZN9Arguments17SharedArchivePathE$$
  62   FILTER_SYMBOLS_AWK_SCRIPT := \
  63       '{ \
  64         if ($$3 ~ /$(FILTER_SYMBOLS_PATTERN)/) print $$3; \
  65       }'
  66 
  67 else ifeq ($(call isTargetOs, macosx), true)
  68   # nm on macosx prints out "warning: nm: no name list" to stderr for
  69   # files without symbols. Hide this, even at the expense of hiding real errors.
  70   DUMP_SYMBOLS_CMD := $(NM) -Uj *.o 2> /dev/null
  71   ifneq ($(FILTER_SYMBOLS_PATTERN), )
  72     FILTER_SYMBOLS_PATTERN := $(FILTER_SYMBOLS_PATTERN)|
  73   endif
  74   FILTER_SYMBOLS_PATTERN := $(FILTER_SYMBOLS_PATTERN)^_ZTV|^gHotSpotVM
  75   FILTER_SYMBOLS_AWK_SCRIPT := \
  76       '{ \
  77         if ($$3 ~ /$(FILTER_SYMBOLS_PATTERN)/) print $$3; \
  78       }'
  79 
  80 # NOTE: The script is from the old build. It is broken and finds no symbols.
  81 # The script below might be what was intended, but it failes to link with tons
  82 # of 'cannot export hidden symbol vtable for X'.
  83 #  '{ if ($$1 ~ /^__ZTV/ || $$1 ~ /^_gHotSpotVM/) print substr($$1, 2) }'
  84 else ifeq ($(call isTargetOs, aix), true)
  85   # NOTE: The old build had the solution below. This should to be fixed in
  86   # configure instead.
  87 
  88   # On AIX we have to prevent that we pick up the 'nm' version from the GNU binutils
  89   # which may be installed under /opt/freeware/bin. So better use an absolute path here!
  90   # NM=/usr/bin/nm
  91 
  92   DUMP_SYMBOLS_CMD := $(NM) -X64 -B -C *.o
  93   FILTER_SYMBOLS_AWK_SCRIPT := \
  94       '{ \
  95         if (($$2="d" || $$2="D") && ($$3 ~ /^__vft/ || $$3 ~ /^gHotSpotVM/)) print $$3; \
  96         if ($$3 ~ /^UseSharedSpaces$$/) print $$3; \
  97         if ($$3 ~ /^SharedArchivePath__9Arguments$$/) print $$3; \
  98        }'
  99 
 100 else ifeq ($(call isTargetOs, windows), true)
 101   DUMP_SYMBOLS_CMD := $(DUMPBIN) -symbols *.obj
 102   FILTER_SYMBOLS_AWK_SCRIPT := \
 103       '{ \
 104         if ($$7 ~ /??_7.*@@6B@/ && $$7 !~ /type_info/) print $$7; \
 105       }'
 106 
 107 else
 108   $(error Unknown target OS $(OPENJDK_TARGET_OS) in JvmMapfile.gmk)
 109 endif
 110 
 111 # A more correct solution would be to send BUILD_LIBJVM_ALL_OBJS instead of
 112 # cd && *.o, but this will result in very long command lines, which is
 113 # problematic on some platforms.
 114 $(JVM_OUTPUTDIR)/symbols-objects: $(BUILD_LIBJVM_ALL_OBJS)
 115         $(call LogInfo, Generating symbol list from object files)
 116         $(CD) $(JVM_OUTPUTDIR)/objs && \
 117           $(DUMP_SYMBOLS_CMD) | $(NAWK) $(FILTER_SYMBOLS_AWK_SCRIPT) | $(SORT) -u > $@
 118 
 119 SYMBOLS_SRC += $(JVM_OUTPUTDIR)/symbols-objects
 120 
 121 ################################################################################
 122 # Now concatenate all symbol lists into a single file and remove comments.
 123 
 124 $(JVM_OUTPUTDIR)/symbols: $(SYMBOLS_SRC)
 125         $(SED) -e '/^#/d' $^ > $@
 126 
 127 ################################################################################
 128 # Finally convert the symbol list into a platform-specific mapfile
 129 
 130 ifeq ($(call isTargetOs, macosx), true)
 131   # On macosx, we need to add a leading underscore
 132   define create-mapfile-work
 133           $(AWK) '{ if ($$0 ~ ".") { print "  _" $$0 } }'  < $^ > $@.tmp
 134   endef
 135 else ifeq ($(call isTargetOs, windows), true)
 136   # On windows, add an 'EXPORTS' header
 137   define create-mapfile-work
 138           $(ECHO) "EXPORTS" > $@.tmp
 139           $(AWK) '{ if ($$0 ~ ".") { print "  " $$0 } }'  < $^ >> $@.tmp
 140   endef
 141 else
 142   # Assume standard linker script
 143   define create-mapfile-work
 144           $(PRINTF) "SUNWprivate_1.1 { \n  global: \n" > $@.tmp
 145           $(AWK) '{ if ($$0 ~ ".") { print "    " $$0 ";" } }' < $^ >> $@.tmp
 146           $(PRINTF) "  local: \n    *; \n }; \n" >> $@.tmp
 147   endef
 148 endif
 149 
 150 define create-mapfile
 151         $(call LogInfo, Creating mapfile)
 152         $(call MakeDir, $(@D))
 153         $(call create-mapfile-work)
 154         $(RM) $@
 155         $(MV) $@.tmp $@
 156 endef
 157 
 158 $(JVM_MAPFILE): $(JVM_OUTPUTDIR)/symbols
 159         $(call create-mapfile)