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