xref: /titanic_50/usr/src/common/mapfiles/gen/Makefile (revision 7b07063d906859b2be1e88791f801b3c96e432f6)
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.
25*7b07063dSIgor Kozhukhov# Copyright 2015 Igor Kozhukhov <ikozhukhov@gmail.com>
2624da5b34Srie#
2724da5b34Srie
2824da5b34Srieinclude		$(SRC)/Makefile.master
2924da5b34Srie
3024da5b34SrieFILES=	\
3124da5b34Srie		$(MACH)_cc_map.noexeglobs \
3224da5b34Srie		$(MACH)_gcc_map.noexeglobs
3324da5b34Srie
3424da5b34Srie$(BUILD64)FILES += \
3524da5b34Srie		$(MACH64)_cc_map.noexeglobs \
3624da5b34Srie		$(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
4824da5b34Srielint:
4924da5b34Srie
5024da5b34Srieclean:
5124da5b34Srie		$(RM) $(SYMS1) $(SYMS2) $(MAIN1) $(MAIN2)
5224da5b34Srie
5324da5b34Srieclobber:	clean
5424da5b34Srie		$(RM) $(FILES)
5524da5b34Srie
5624da5b34Srie# A number of dynamic executables have their own definitions of interfaces that
5724da5b34Srie# exist in system libraries.  To prevent name-space pollution it is desirable
5824da5b34Srie# to demote the interfaces within these executable to locals.  However, various
5924da5b34Srie# symbols defined by the compiler drivers crt/values files need to remain
6024da5b34Srie# global in any dynamic object that includes these files.  These symbols
6124da5b34Srie# interpose on symbols in libc, or provide call backs for other system
6224da5b34Srie# libraries.  The various compiler drivers (cc and gcc), and the crt/values
6324da5b34Srie# files that these drivers are configured to include, differ between the
6424da5b34Srie# various compilations environments (platform, 32/64-bit).  Therefore, the
6524da5b34Srie# only means of creating a mapfile to demote symbols is to dynamically generate
6624da5b34Srie# the mapfile for a specific compilation environment.
6724da5b34Srie#
6824da5b34Srie# Here, template mapfiles are used to generate a number of compilation specific
6924da5b34Srie# mapfiles.  These mapfiles are referenced by components of the build through
7024da5b34Srie# the MAPFILE.NGB macro defined in Makefile.master.  These dynamically created
7124da5b34Srie# mapfiles are not delivered into the $ROOT area, and therefore are not
7224da5b34Srie# delivered as packaged components of the OSNet.
7324da5b34Srie
7424da5b34Srie$(MACH)_cc_map.noexeglobs :=	LINK =	$(LINK.c)
7524da5b34Srie$(MACH64)_cc_map.noexeglobs :=	LINK =	$(LINK64.c)
7624da5b34Srie
7724da5b34Srie$(MACH)_gcc_map.noexeglobs :=	CC =	$(ONBLD_TOOLS)/bin/$(MACH)/cw -_gcc
7824da5b34Srie$(MACH)_gcc_map.noexeglobs :=	LINK =	$(LINK.c)
7924da5b34Srie$(MACH64)_gcc_map.noexeglobs :=	CC =	$(ONBLD_TOOLS)/bin/$(MACH)/cw -_gcc
8024da5b34Srie$(MACH64)_gcc_map.noexeglobs :=	LINK =	$(LINK64.c)
8124da5b34Srie
8224da5b34Srie# This generic target creates two dynamic executables from an empty "main"
8324da5b34Srie# program.  These objects are not executed, but are analyzed to determine the
8424da5b34Srie# global symbols each provides.
8524da5b34Srie#
8624da5b34Srie# The first executable demotes a family of known interfaces to local and allows
8724da5b34Srie# all other symbol definitions to remain global.  This executables provides the
8824da5b34Srie# base for discovering all symbol definitions provided by the various
8924da5b34Srie# compilation environments.  The second executable demotes all symbols to
9024da5b34Srie# locals.  Within both executables, some symbols remain globals (_end, _etext,
9124da5b34Srie# etc.) as the link-editor has special knowledge of these symbols and their
9224da5b34Srie# expected visibility requirements.  By inspecting the deferences between the
9324da5b34Srie# global symbols within the two executables, a mapfile can be generated to
9424da5b34Srie# ensure the symbols defined by the compilation environments files remain
9524da5b34Srie# global.
9624da5b34Srie
9724da5b34Srie%map.noexeglobs:main.c $(TEMPLATE1) $(TEMPLATE2)
9824da5b34Srie	$(LINK) -o $(MAIN1) -M$(TEMPLATE1) main.c
9924da5b34Srie	$(ELFDUMP) -s -N.dynsym $(MAIN1) | $(EGREP) "WEAK|GLOB" | \
100*7b07063dSIgor Kozhukhov	    $(GREP) -v UNDEF | $(AWK) '{print $$9 }' | $(SORT) > $(SYMS1)
10124da5b34Srie	$(LINK) -o $(MAIN2) -M$(TEMPLATE2) main.c
10224da5b34Srie	$(ELFDUMP) -s -N.dynsym $(MAIN2) | $(EGREP) "WEAK|GLOB" | \
103*7b07063dSIgor Kozhukhov	    $(GREP) -v UNDEF | $(AWK) '{print $$9 }' | $(SORT) > $(SYMS2)
10424da5b34Srie	$(ECHO) "# GENERATED FILE - DO NOT EDIT"	>  $@
10524da5b34Srie	$(GREP) MAP-HEAD $(TEMPLATE2) | \
10624da5b34Srie	    $(SED) -e "s/	*# MAP-HEAD//"		>> $@
10724da5b34Srie	$(DIFF) $(SYMS1) $(SYMS2) | $(GREP) "^<" | \
10824da5b34Srie	    $(SED) -e "s/^< \(.*\)/        \1;/"	>> $@
10924da5b34Srie	$(GREP) MAP-TAIL $(TEMPLATE2) | \
11024da5b34Srie	    $(SED) -e "s/	*# MAP-TAIL//"		>> $@
11124da5b34Srie	$(RM) $(SYMS1) $(SYMS2) $(MAIN1) $(MAIN2)
112