124da5b34Srie# 224da5b34Srie# CDDL HEADER START 324da5b34Srie# 424da5b34Srie# The contents of this file are subject to the terms of the 524da5b34Srie# Common Development and Distribution License (the "License"). 624da5b34Srie# You may not use this file except in compliance with the License. 724da5b34Srie# 824da5b34Srie# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 924da5b34Srie# or http://www.opensolaris.org/os/licensing. 1024da5b34Srie# See the License for the specific language governing permissions 1124da5b34Srie# and limitations under the License. 1224da5b34Srie# 1324da5b34Srie# When distributing Covered Code, include this CDDL HEADER in each 1424da5b34Srie# file and include the License file at usr/src/OPENSOLARIS.LICENSE. 1524da5b34Srie# If applicable, add the following below this CDDL HEADER, with the 1624da5b34Srie# fields enclosed by brackets "[]" replaced with your own identifying 1724da5b34Srie# information: Portions Copyright [yyyy] [name of copyright owner] 1824da5b34Srie# 1924da5b34Srie# CDDL HEADER END 2024da5b34Srie# 2124da5b34Srie 2224da5b34Srie# 2324da5b34Srie# Copyright 2007 Sun Microsystems, Inc. All rights reserved. 2424da5b34Srie# Use is subject to license terms. 257b07063dSIgor Kozhukhov# Copyright 2015 Igor Kozhukhov <ikozhukhov@gmail.com> 2624da5b34Srie# 2724da5b34Srie 2824da5b34Srieinclude $(SRC)/Makefile.master 2924da5b34Srie 3024da5b34Srie 31*8c426718SRichard LoweFILES= $(MACH)_gcc_map.noexeglobs 32aa9ef484SJohn Levon 335801b0f0SToomas SoomeNATIVE_LIBS += libc.so 345801b0f0SToomas SoomeLDFLAGS += $(BDIRECT) 355801b0f0SToomas Soome 36*8c426718SRichard Lowe$(BUILD64)FILES += $(MACH64)_gcc_map.noexeglobs 3724da5b34Srie 3824da5b34SrieSYMS1= syms.1 3924da5b34SrieSYMS2= syms.2 4024da5b34SrieMAIN1= main.1 4124da5b34SrieMAIN2= main.2 4224da5b34Srie 4324da5b34SrieTEMPLATE1= map.noexeglobs.1.template 4424da5b34SrieTEMPLATE2= map.noexeglobs.2.template 4524da5b34Srie 4624da5b34Srieall install: $(FILES) 4724da5b34Srie 4824da5b34Srieclean: 4924da5b34Srie $(RM) $(SYMS1) $(SYMS2) $(MAIN1) $(MAIN2) 5024da5b34Srie 5124da5b34Srieclobber: clean 5224da5b34Srie $(RM) $(FILES) 5324da5b34Srie 5424da5b34Srie# A number of dynamic executables have their own definitions of interfaces that 5524da5b34Srie# exist in system libraries. To prevent name-space pollution it is desirable 5624da5b34Srie# to demote the interfaces within these executable to locals. However, various 5724da5b34Srie# symbols defined by the compiler drivers crt/values files need to remain 5824da5b34Srie# global in any dynamic object that includes these files. These symbols 5924da5b34Srie# interpose on symbols in libc, or provide call backs for other system 6024da5b34Srie# libraries. The various compiler drivers (cc and gcc), and the crt/values 6124da5b34Srie# files that these drivers are configured to include, differ between the 6224da5b34Srie# various compilations environments (platform, 32/64-bit). Therefore, the 6324da5b34Srie# only means of creating a mapfile to demote symbols is to dynamically generate 6424da5b34Srie# the mapfile for a specific compilation environment. 6524da5b34Srie# 6624da5b34Srie# Here, template mapfiles are used to generate a number of compilation specific 6724da5b34Srie# mapfiles. These mapfiles are referenced by components of the build through 6824da5b34Srie# the MAPFILE.NGB macro defined in Makefile.master. These dynamically created 6924da5b34Srie# mapfiles are not delivered into the $ROOT area, and therefore are not 7024da5b34Srie# delivered as packaged components of the OSNet. 7124da5b34Srie 7224da5b34Srie$(MACH)_cc_map.noexeglobs := LINK = $(LINK.c) 7324da5b34Srie$(MACH64)_cc_map.noexeglobs := LINK = $(LINK64.c) 7424da5b34Srie$(MACH)_gcc_map.noexeglobs := LINK = $(LINK.c) 7524da5b34Srie$(MACH64)_gcc_map.noexeglobs := LINK = $(LINK64.c) 76aa9ef484SJohn Levon 7724da5b34Srie# This generic target creates two dynamic executables from an empty "main" 7824da5b34Srie# program. These objects are not executed, but are analyzed to determine the 7924da5b34Srie# global symbols each provides. 8024da5b34Srie# 8124da5b34Srie# The first executable demotes a family of known interfaces to local and allows 8224da5b34Srie# all other symbol definitions to remain global. This executables provides the 8324da5b34Srie# base for discovering all symbol definitions provided by the various 8424da5b34Srie# compilation environments. The second executable demotes all symbols to 8524da5b34Srie# locals. Within both executables, some symbols remain globals (_end, _etext, 8624da5b34Srie# etc.) as the link-editor has special knowledge of these symbols and their 8724da5b34Srie# expected visibility requirements. By inspecting the deferences between the 8824da5b34Srie# global symbols within the two executables, a mapfile can be generated to 8924da5b34Srie# ensure the symbols defined by the compilation environments files remain 9024da5b34Srie# global. 9124da5b34Srie 9224da5b34Srie%map.noexeglobs:main.c $(TEMPLATE1) $(TEMPLATE2) 9385f4cb87SRichard Lowe $(LINK) -o $(MAIN1) -Wl,-M$(TEMPLATE1) main.c 9424da5b34Srie $(ELFDUMP) -s -N.dynsym $(MAIN1) | $(EGREP) "WEAK|GLOB" | \ 957b07063dSIgor Kozhukhov $(GREP) -v UNDEF | $(AWK) '{print $$9 }' | $(SORT) > $(SYMS1) 9685f4cb87SRichard Lowe $(LINK) -o $(MAIN2) -Wl,-M$(TEMPLATE2) main.c 9724da5b34Srie $(ELFDUMP) -s -N.dynsym $(MAIN2) | $(EGREP) "WEAK|GLOB" | \ 987b07063dSIgor Kozhukhov $(GREP) -v UNDEF | $(AWK) '{print $$9 }' | $(SORT) > $(SYMS2) 9924da5b34Srie $(ECHO) "# GENERATED FILE - DO NOT EDIT" > $@ 10024da5b34Srie $(GREP) MAP-HEAD $(TEMPLATE2) | \ 10124da5b34Srie $(SED) -e "s/ *# MAP-HEAD//" >> $@ 10224da5b34Srie $(DIFF) $(SYMS1) $(SYMS2) | $(GREP) "^<" | \ 10324da5b34Srie $(SED) -e "s/^< \(.*\)/ \1;/" >> $@ 10424da5b34Srie $(GREP) MAP-TAIL $(TEMPLATE2) | \ 10524da5b34Srie $(SED) -e "s/ *# MAP-TAIL//" >> $@ 10624da5b34Srie $(RM) $(SYMS1) $(SYMS2) $(MAIN1) $(MAIN2) 107