xref: /illumos-gate/usr/src/common/mapfiles/gen/Makefile (revision 8c4267180173328ebba9487634f0f232387d067f)
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
28include		$(SRC)/Makefile.master
29
30
31FILES=	$(MACH)_gcc_map.noexeglobs
32
33NATIVE_LIBS	+= libc.so
34LDFLAGS		+= $(BDIRECT)
35
36$(BUILD64)FILES += $(MACH64)_gcc_map.noexeglobs
37
38SYMS1=		syms.1
39SYMS2=		syms.2
40MAIN1=		main.1
41MAIN2=		main.2
42
43TEMPLATE1=	map.noexeglobs.1.template
44TEMPLATE2=	map.noexeglobs.2.template
45
46all install:	$(FILES)
47
48clean:
49		$(RM) $(SYMS1) $(SYMS2) $(MAIN1) $(MAIN2)
50
51clobber:	clean
52		$(RM) $(FILES)
53
54# A number of dynamic executables have their own definitions of interfaces that
55# exist in system libraries.  To prevent name-space pollution it is desirable
56# to demote the interfaces within these executable to locals.  However, various
57# symbols defined by the compiler drivers crt/values files need to remain
58# global in any dynamic object that includes these files.  These symbols
59# interpose on symbols in libc, or provide call backs for other system
60# libraries.  The various compiler drivers (cc and gcc), and the crt/values
61# files that these drivers are configured to include, differ between the
62# various compilations environments (platform, 32/64-bit).  Therefore, the
63# only means of creating a mapfile to demote symbols is to dynamically generate
64# the mapfile for a specific compilation environment.
65#
66# Here, template mapfiles are used to generate a number of compilation specific
67# mapfiles.  These mapfiles are referenced by components of the build through
68# the MAPFILE.NGB macro defined in Makefile.master.  These dynamically created
69# mapfiles are not delivered into the $ROOT area, and therefore are not
70# delivered as packaged components of the OSNet.
71
72$(MACH)_cc_map.noexeglobs :=	LINK =	$(LINK.c)
73$(MACH64)_cc_map.noexeglobs :=	LINK =	$(LINK64.c)
74$(MACH)_gcc_map.noexeglobs :=	LINK =	$(LINK.c)
75$(MACH64)_gcc_map.noexeglobs :=	LINK =	$(LINK64.c)
76
77# This generic target creates two dynamic executables from an empty "main"
78# program.  These objects are not executed, but are analyzed to determine the
79# global symbols each provides.
80#
81# The first executable demotes a family of known interfaces to local and allows
82# all other symbol definitions to remain global.  This executables provides the
83# base for discovering all symbol definitions provided by the various
84# compilation environments.  The second executable demotes all symbols to
85# locals.  Within both executables, some symbols remain globals (_end, _etext,
86# etc.) as the link-editor has special knowledge of these symbols and their
87# expected visibility requirements.  By inspecting the deferences between the
88# global symbols within the two executables, a mapfile can be generated to
89# ensure the symbols defined by the compilation environments files remain
90# global.
91
92%map.noexeglobs:main.c $(TEMPLATE1) $(TEMPLATE2)
93	$(LINK) -o $(MAIN1) -Wl,-M$(TEMPLATE1) main.c
94	$(ELFDUMP) -s -N.dynsym $(MAIN1) | $(EGREP) "WEAK|GLOB" | \
95	    $(GREP) -v UNDEF | $(AWK) '{print $$9 }' | $(SORT) > $(SYMS1)
96	$(LINK) -o $(MAIN2) -Wl,-M$(TEMPLATE2) main.c
97	$(ELFDUMP) -s -N.dynsym $(MAIN2) | $(EGREP) "WEAK|GLOB" | \
98	    $(GREP) -v UNDEF | $(AWK) '{print $$9 }' | $(SORT) > $(SYMS2)
99	$(ECHO) "# GENERATED FILE - DO NOT EDIT"	>  $@
100	$(GREP) MAP-HEAD $(TEMPLATE2) | \
101	    $(SED) -e "s/	*# MAP-HEAD//"		>> $@
102	$(DIFF) $(SYMS1) $(SYMS2) | $(GREP) "^<" | \
103	    $(SED) -e "s/^< \(.*\)/        \1;/"	>> $@
104	$(GREP) MAP-TAIL $(TEMPLATE2) | \
105	    $(SED) -e "s/	*# MAP-TAIL//"		>> $@
106	$(RM) $(SYMS1) $(SYMS2) $(MAIN1) $(MAIN2)
107