summaryrefslogtreecommitdiff
path: root/usr/src/common/mapfiles/gen/Makefile
blob: 300683f981b3e0b458777dcb7574bfca5dfb12ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License (the "License").
# You may not use this file except in compliance with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#

#
# Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
# Copyright 2015 Igor Kozhukhov <ikozhukhov@gmail.com>
#

include		$(SRC)/Makefile.master


$(__GNUC)FILES=	$(MACH)_gcc_map.noexeglobs
$(__SUNC)FILES= $(MACH)_cc_map.noexeglobs

NATIVE_LIBS	+= libc.so
LDFLAGS		+= $(BDIRECT)

$(__GNUC)$(BUILD64)FILES += $(MACH64)_gcc_map.noexeglobs
$(__SUNC)$(BUILD64)FILES += $(MACH64)_cc_map.noexeglobs

SYMS1=		syms.1
SYMS2=		syms.2
MAIN1=		main.1
MAIN2=		main.2

TEMPLATE1=	map.noexeglobs.1.template
TEMPLATE2=	map.noexeglobs.2.template

all install:	$(FILES)

clean:
		$(RM) $(SYMS1) $(SYMS2) $(MAIN1) $(MAIN2)

clobber:	clean
		$(RM) $(FILES)

# A number of dynamic executables have their own definitions of interfaces that
# exist in system libraries.  To prevent name-space pollution it is desirable
# to demote the interfaces within these executable to locals.  However, various
# symbols defined by the compiler drivers crt/values files need to remain
# global in any dynamic object that includes these files.  These symbols
# interpose on symbols in libc, or provide call backs for other system
# libraries.  The various compiler drivers (cc and gcc), and the crt/values
# files that these drivers are configured to include, differ between the
# various compilations environments (platform, 32/64-bit).  Therefore, the
# only means of creating a mapfile to demote symbols is to dynamically generate
# the mapfile for a specific compilation environment.
#
# Here, template mapfiles are used to generate a number of compilation specific
# mapfiles.  These mapfiles are referenced by components of the build through
# the MAPFILE.NGB macro defined in Makefile.master.  These dynamically created
# mapfiles are not delivered into the $ROOT area, and therefore are not
# delivered as packaged components of the OSNet.

$(MACH)_cc_map.noexeglobs :=	LINK =	$(LINK.c)
$(MACH64)_cc_map.noexeglobs :=	LINK =	$(LINK64.c)
$(MACH)_gcc_map.noexeglobs :=	LINK =	$(LINK.c)
$(MACH64)_gcc_map.noexeglobs :=	LINK =	$(LINK64.c)

# This generic target creates two dynamic executables from an empty "main"
# program.  These objects are not executed, but are analyzed to determine the
# global symbols each provides.
#
# The first executable demotes a family of known interfaces to local and allows
# all other symbol definitions to remain global.  This executables provides the
# base for discovering all symbol definitions provided by the various
# compilation environments.  The second executable demotes all symbols to
# locals.  Within both executables, some symbols remain globals (_end, _etext,
# etc.) as the link-editor has special knowledge of these symbols and their
# expected visibility requirements.  By inspecting the deferences between the
# global symbols within the two executables, a mapfile can be generated to
# ensure the symbols defined by the compilation environments files remain
# global.

%map.noexeglobs:main.c $(TEMPLATE1) $(TEMPLATE2)
	$(LINK) -o $(MAIN1) -Wl,-M$(TEMPLATE1) main.c
	$(ELFDUMP) -s -N.dynsym $(MAIN1) | $(EGREP) "WEAK|GLOB" | \
	    $(GREP) -v UNDEF | $(AWK) '{print $$9 }' | $(SORT) > $(SYMS1)
	$(LINK) -o $(MAIN2) -Wl,-M$(TEMPLATE2) main.c
	$(ELFDUMP) -s -N.dynsym $(MAIN2) | $(EGREP) "WEAK|GLOB" | \
	    $(GREP) -v UNDEF | $(AWK) '{print $$9 }' | $(SORT) > $(SYMS2)
	$(ECHO) "# GENERATED FILE - DO NOT EDIT"	>  $@
	$(GREP) MAP-HEAD $(TEMPLATE2) | \
	    $(SED) -e "s/	*# MAP-HEAD//"		>> $@
	$(DIFF) $(SYMS1) $(SYMS2) | $(GREP) "^<" | \
	    $(SED) -e "s/^< \(.*\)/        \1;/"	>> $@
	$(GREP) MAP-TAIL $(TEMPLATE2) | \
	    $(SED) -e "s/	*# MAP-TAIL//"		>> $@
	$(RM) $(SYMS1) $(SYMS2) $(MAIN1) $(MAIN2)