1 #
   2 # CDDL HEADER START
   3 #
   4 # The contents of this file are subject to the terms of the
   5 # Common Development and Distribution License (the "License").
   6 # You may not use this file except in compliance with the License.
   7 #
   8 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
   9 # or http://www.opensolaris.org/os/licensing.
  10 # See the License for the specific language governing permissions
  11 # and limitations under the License.
  12 #
  13 # When distributing Covered Code, include this CDDL HEADER in each
  14 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
  15 # If applicable, add the following below this CDDL HEADER, with the
  16 # fields enclosed by brackets "[]" replaced with your own identifying
  17 # information: Portions Copyright [yyyy] [name of copyright owner]
  18 #
  19 # CDDL HEADER END
  20 #
  21 
  22 #
  23 # Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  24 # Use is subject to license terms.
  25 # Copyright 2015 Igor Kozhukhov <ikozhukhov@gmail.com>
  26 #
  27 
  28 include         $(SRC)/Makefile.master
  29 
  30 FILES=  \
  31                 $(MACH)_cc_map.noexeglobs \
  32                 $(MACH)_gcc_map.noexeglobs
  33 
  34 NATIVE_LIBS =   libc.so
  35 LDFLAGS +=      -B direct
  36 
  37 $(BUILD64)FILES += \
  38                 $(MACH64)_cc_map.noexeglobs \
  39                 $(MACH64)_gcc_map.noexeglobs
  40 
  41 SYMS1=          syms.1
  42 SYMS2=          syms.2
  43 MAIN1=          main.1
  44 MAIN2=          main.2
  45 
  46 TEMPLATE1=      map.noexeglobs.1.template
  47 TEMPLATE2=      map.noexeglobs.2.template
  48 
  49 all install:    $(FILES)
  50 
  51 lint:
  52 
  53 clean:
  54                 $(RM) $(SYMS1) $(SYMS2) $(MAIN1) $(MAIN2)
  55 
  56 clobber:        clean
  57                 $(RM) $(FILES)
  58 
  59 # A number of dynamic executables have their own definitions of interfaces that
  60 # exist in system libraries.  To prevent name-space pollution it is desirable
  61 # to demote the interfaces within these executable to locals.  However, various
  62 # symbols defined by the compiler drivers crt/values files need to remain
  63 # global in any dynamic object that includes these files.  These symbols
  64 # interpose on symbols in libc, or provide call backs for other system
  65 # libraries.  The various compiler drivers (cc and gcc), and the crt/values
  66 # files that these drivers are configured to include, differ between the
  67 # various compilations environments (platform, 32/64-bit).  Therefore, the
  68 # only means of creating a mapfile to demote symbols is to dynamically generate
  69 # the mapfile for a specific compilation environment.
  70 #
  71 # Here, template mapfiles are used to generate a number of compilation specific
  72 # mapfiles.  These mapfiles are referenced by components of the build through
  73 # the MAPFILE.NGB macro defined in Makefile.master.  These dynamically created
  74 # mapfiles are not delivered into the $ROOT area, and therefore are not
  75 # delivered as packaged components of the OSNet.
  76 
  77 $(MACH)_cc_map.noexeglobs :=    LINK =  $(LINK.c)
  78 $(MACH64)_cc_map.noexeglobs :=  LINK =  $(LINK64.c)
  79 
  80 $(MACH)_gcc_map.noexeglobs :=   CC =    $(ONBLD_TOOLS)/bin/$(MACH)/cw -_gcc
  81 $(MACH)_gcc_map.noexeglobs :=   LINK =  $(LINK.c)
  82 $(MACH64)_gcc_map.noexeglobs := CC =    $(ONBLD_TOOLS)/bin/$(MACH)/cw -_gcc
  83 $(MACH64)_gcc_map.noexeglobs := LINK =  $(LINK64.c)
  84 
  85 # This generic target creates two dynamic executables from an empty "main"
  86 # program.  These objects are not executed, but are analyzed to determine the
  87 # global symbols each provides.
  88 #
  89 # The first executable demotes a family of known interfaces to local and allows
  90 # all other symbol definitions to remain global.  This executables provides the
  91 # base for discovering all symbol definitions provided by the various
  92 # compilation environments.  The second executable demotes all symbols to
  93 # locals.  Within both executables, some symbols remain globals (_end, _etext,
  94 # etc.) as the link-editor has special knowledge of these symbols and their
  95 # expected visibility requirements.  By inspecting the deferences between the
  96 # global symbols within the two executables, a mapfile can be generated to
  97 # ensure the symbols defined by the compilation environments files remain
  98 # global.
  99 
 100 %map.noexeglobs:main.c $(TEMPLATE1) $(TEMPLATE2)
 101         $(LINK) -o $(MAIN1) -M$(TEMPLATE1) main.c
 102         $(ELFDUMP) -s -N.dynsym $(MAIN1) | $(EGREP) "WEAK|GLOB" | \
 103             $(GREP) -v UNDEF | $(AWK) '{print $$9 }' | $(SORT) > $(SYMS1)
 104         $(LINK) -o $(MAIN2) -M$(TEMPLATE2) main.c
 105         $(ELFDUMP) -s -N.dynsym $(MAIN2) | $(EGREP) "WEAK|GLOB" | \
 106             $(GREP) -v UNDEF | $(AWK) '{print $$9 }' | $(SORT) > $(SYMS2)
 107         $(ECHO) "# GENERATED FILE - DO NOT EDIT"        >  $@
 108         $(GREP) MAP-HEAD $(TEMPLATE2) | \
 109             $(SED) -e "s/       *# MAP-HEAD//"          >> $@
 110         $(DIFF) $(SYMS1) $(SYMS2) | $(GREP) "^<" | \
 111             $(SED) -e "s/^< \(.*\)/        \1;/"     >> $@
 112         $(GREP) MAP-TAIL $(TEMPLATE2) | \
 113             $(SED) -e "s/       *# MAP-TAIL//"          >> $@
 114         $(RM) $(SYMS1) $(SYMS2) $(MAIN1) $(MAIN2)