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.
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.
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]
23 # Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved.
24 # Copyright 2016 Joyent, Inc.
25 # Copyright (c) 2013, OmniTI Computer Consulting, Inc. All rights reserved.
26 # Copyright 2013 Garrett D'Amore <garrett@damore.org>
27 # Copyright 2017 Nexenta Systems, Inc.
30 LIBCDIR= $(SRC)/lib/libc
36 # include comm page definitions
37 include $(SRC)/lib/commpage/Makefile.shared.com
38 include $(SRC)/lib/commpage/Makefile.shared.targ
42 # objects are grouped by source directory
127 arc4random_uniform.o \
162 sync_instruction_memory.o
164 # sysobjs that contain large-file interfaces
316 __clock_gettime_sys.o \
319 _lwp_mutex_unlock.o \
338 # objects under $(LIBCDIR)/port which contain transitional large file interfaces
348 # objects from source under $(LIBCDIR)/port
385 ascii_strncasecmp.o \
647 # c89 variants to support 32-bit size of c89 u/intmax_t (32-bit libc only)
659 # portable stdio objects that contain large file interfaces.
660 # Note: fopen64 is a special case, as we build it small.
905 # objects that implement the transitional large file API
1019 $(THREADSMACHOBJS) \
1033 # NOTE: libc.so.1 must be linked with the minimal crti.o and crtn.o
1034 # modules whose source is provided in the $(SRC)/lib/common directory.
1035 # This must be done because otherwise the Sun C compiler would insert
1036 # its own versions of these modules and those versions contain code
1037 # to call out to C++ initialization functions. Such C++ initialization
1038 # functions can call back into libc before thread initialization is
1039 # complete and this leads to segmentation violations and other problems.
1040 # Since libc contains no C++ code, linking with the minimal crti.o and
1041 # crtn.o modules is safe and avoids the problems described above.
1042 OBJECTS= $(CRTI) $(MOSTOBJS) $(CRTN)
1043 CRTSRCS= ../../common/i386
1045 LDPASS_OFF= $(POUND_SIGN)
1047 # include common library definitions
1048 include ../../Makefile.lib
1050 # we need to override the default SONAME here because we might
1051 # be building a variant object (still libc.so.1, but different filename)
1054 CFLAGS += $(CCVERBOSE) $(CTF_FLAGS)
1056 # This is necessary to avoid problems with calling _ex_unwind().
1057 # We probably don't want any inlining anyway.
1059 CFLAGS += $(XINLINE)
1061 CERRWARN += -_gcc=-Wno-parentheses
1062 CERRWARN += -_gcc=-Wno-switch
1063 CERRWARN += -_gcc=-Wno-uninitialized
1064 CERRWARN += -_gcc=-Wno-unused-value
1065 CERRWARN += -_gcc=-Wno-unused-label
1066 CERRWARN += -_gcc=-Wno-unused-variable
1067 CERRWARN += -_gcc=-Wno-type-limits
1068 CERRWARN += -_gcc=-Wno-char-subscripts
1069 CERRWARN += -_gcc=-Wno-clobbered
1070 CERRWARN += -_gcc=-Wno-unused-function
1071 CERRWARN += -_gcc=-Wno-address
1073 # Setting THREAD_DEBUG = -DTHREAD_DEBUG (make THREAD_DEBUG=-DTHREAD_DEBUG ...)
1074 # enables ASSERT() checking in the threads portion of the library.
1075 # This is automatically enabled for DEBUG builds, not for non-debug builds.
1077 $(NOT_RELEASE_BUILD)THREAD_DEBUG = -DTHREAD_DEBUG
1079 # Make string literals read-only to save memory.
1080 CFLAGS += $(XSTRCONST)
1082 ALTPICS= $(TRACEOBJS:%=pics/%)
1084 $(DYNLIB) := BUILD.SO = $(LD) -o $@ -G $(DYNFLAGS) $(PICS) $(ALTPICS) \
1085 $(EXTPICS) $(LDLIBS)
1087 MAPFILES = $(LIBCDIR)/port/mapfile-vers
1090 # EXTN_CPPFLAGS and EXTN_CFLAGS set in enclosing Makefile
1092 CFLAGS += $(EXTN_CFLAGS)
1093 CPPFLAGS= -D_REENTRANT -Di386 $(EXTN_CPPFLAGS) $(THREAD_DEBUG) \
1094 -I$(LIBCBASE)/inc -I$(LIBCDIR)/inc $(CPPFLAGS.master)
1095 ASFLAGS= $(AS_PICFLAGS) -P -D__STDC__ -D_ASM $(CPPFLAGS) $(i386_AS_XARCH)
1097 # As a favor to the dtrace syscall provider, libc still calls the
1098 # old syscall traps that have been obsoleted by the *at() interfaces.
1099 # Delete this to compile libc using only the new *at() system call traps
1100 CPPFLAGS += -D_RETAIN_OLD_SYSCALLS
1102 # Inform the run-time linker about libc specialized initialization
1103 RTLDINFO = -z rtldinfo=tls_rtldinfo
1104 DYNFLAGS += $(RTLDINFO)
1106 # Force libc's internal references to be resolved immediately upon loading
1107 # in order to avoid critical region problems. Since almost all libc symbols
1108 # are marked 'protected' in the mapfiles, this is a minimal set (15 to 20).
1111 DYNFLAGS += -e __rtboot
1112 DYNFLAGS += $(EXTN_DYNFLAGS)
1114 # Inform the kernel about the initial DTrace area (in case
1115 # libc is being used as the interpreter / runtime linker).
1116 DTRACE_DATA = -zdtrace=dtrace_data
1117 DYNFLAGS += $(DTRACE_DATA)
1119 # DTrace needs an executable data segment.
1122 BUILD.s= $(AS) $(ASFLAGS) $< -o $@
1124 # Override this top level flag so the compiler builds in its native
1125 # C99 mode. This has been enabled to support the complex arithmetic
1127 C99MODE= $(C99_ENABLE)
1129 # libc method of building an archive
1130 # The "$(GREP) -v ' L '" part is necessary only until
1131 # lorder is fixed to ignore thread-local variables.
1132 BUILD.AR= $(RM) $@ ; \
1133 $(AR) q $@ `$(LORDER) $(MOSTOBJS:%=$(DIR)/%) | $(GREP) -v ' L ' | $(TSORT)`
1135 # extra files for the clean target
1137 $(LIBCDIR)/port/gen/errlst.c \
1138 $(LIBCDIR)/port/gen/new_list.c \
1148 CLOBBERFILES += $(LIB_PIC)
1150 # list of C source for lint
1152 $(ATOMICOBJS:%.o=$(SRC)/common/atomic/%.c) \
1153 $(XATTROBJS:%.o=$(SRC)/common/xattr/%.c) \
1154 $(COMOBJS:%.o=$(SRC)/common/util/%.c) \
1155 $(DTRACEOBJS:%.o=$(SRC)/common/dtrace/%.c) \
1156 $(PORTFP:%.o=$(LIBCDIR)/port/fp/%.c) \
1157 $(PORTGEN:%.o=$(LIBCDIR)/port/gen/%.c) \
1158 $(PORTI18N:%.o=$(LIBCDIR)/port/i18n/%.c) \
1159 $(PORTLOCALE:%.o=$(LIBCDIR)/port/locale/%.c) \
1160 $(PORTPRINT:%.o=$(LIBCDIR)/port/print/%.c) \
1161 $(PORTREGEX:%.o=$(LIBCDIR)/port/regex/%.c) \
1162 $(PORTSTDIO:%.o=$(LIBCDIR)/port/stdio/%.c) \
1163 $(PORTSYS:%.o=$(LIBCDIR)/port/sys/%.c) \
1164 $(AIOOBJS:%.o=$(LIBCDIR)/port/aio/%.c) \
1165 $(RTOBJS:%.o=$(LIBCDIR)/port/rt/%.c) \
1166 $(SECFLAGSOBJS:%.o=$(SRC)/common/secflags/%.c) \
1167 $(TPOOLOBJS:%.o=$(LIBCDIR)/port/tpool/%.c) \
1168 $(THREADSOBJS:%.o=$(LIBCDIR)/port/threads/%.c) \
1169 $(THREADSMACHOBJS:%.o=$(LIBCDIR)/$(MACH)/threads/%.c) \
1170 $(UNICODEOBJS:%.o=$(SRC)/common/unicode/%.c) \
1171 $(UNWINDMACHOBJS:%.o=$(LIBCDIR)/port/unwind/%.c) \
1172 $(FPOBJS:%.o=$(LIBCDIR)/$(MACH)/fp/%.c) \
1173 $(LIBCBASE)/gen/ecvt.c \
1174 $(LIBCBASE)/gen/makectxt.c \
1175 $(LIBCBASE)/gen/siginfolst.c \
1176 $(LIBCBASE)/gen/siglongjmp.c \
1177 $(LIBCBASE)/gen/strcmp.c \
1178 $(LIBCBASE)/gen/sync_instruction_memory.c \
1179 $(LIBCBASE)/sys/ptrace.c \
1180 $(LIBCBASE)/sys/uadmin.c
1182 # conditional assignments
1183 $(DYNLIB) := CRTI = crti.o
1184 $(DYNLIB) := CRTN = crtn.o
1186 # Files which need the threads .il inline template
1219 thread_interface.o \
1226 THREADS_INLINES = $(LIBCBASE)/threads/i386.il
1227 $(TIL:%=pics/%) := CFLAGS += $(THREADS_INLINES)
1229 # pics/mul64.o := CFLAGS += $(LIBCBASE)/crt/mul64.il
1231 # large-file-aware components that should be built large
1233 $(COMSYSOBJS64:%=pics/%) := \
1234 CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
1236 $(SYSOBJS64:%=pics/%) := \
1237 CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
1239 $(PORTGEN64:%=pics/%) := \
1240 CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
1242 $(PORTREGEX64:%=pics/%) := \
1243 CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
1245 $(PORTSTDIO64:%=pics/%) := \
1246 CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
1248 $(PORTSYS64:%=pics/%) := \
1249 CPPFLAGS += -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64
1251 $(PORTSTDIO_W:%=pics/%) := \
1254 $(PORTPRINT_W:%=pics/%) := \
1257 $(PORTPRINT_C89:%=pics/%) := \
1258 CPPFLAGS += -D_C89_INTMAX32
1260 $(PORTSTDIO_C89:%=pics/%) := \
1261 CPPFLAGS += -D_C89_INTMAX32
1263 $(PORTI18N_COND:%=pics/%) := \
1264 CPPFLAGS += -D_WCS_LONGLONG
1266 pics/arc4random.o := CPPFLAGS += -I$(SRC)/common/crypto/chacha
1268 pics/__clock_gettime.o := CPPFLAGS += $(COMMPAGE_CPPFLAGS)
1272 all: $(LIBS) $(LIB_PIC)
1274 lint := CPPFLAGS += -I$(LIBCDIR)/$(MACH)/fp
1275 lint := CPPFLAGS += -D_MSE_INT_H -D_LCONV_C99
1276 lint := LINTFLAGS += -mn -erroff=E_SUPPRESSION_DIRECTIVE_UNUSED
1280 @$(LINT.c) $(SRCS) $(LDLIBS)
1282 $(LINTLIB):= SRCS=$(LIBCDIR)/port/llib-lc
1283 $(LINTLIB):= CPPFLAGS += -D_MSE_INT_H
1284 $(LINTLIB):= LINTFLAGS=-nvx
1286 # object files that depend on inline template
1287 $(TIL:%=pics/%): $(LIBCBASE)/threads/i386.il
1288 # pics/mul64.o: $(LIBCBASE)/crt/mul64.il
1290 # include common libc targets
1291 include $(LIBCDIR)/Makefile.targ
1293 # We need to strip out all CTF and DOF data from the static library
1294 $(LIB_PIC) := DIR = pics
1295 $(LIB_PIC): pics $$(PICS)
1297 $(MCS) -d -n .SUNW_ctf $@ > /dev/null 2>&1
1298 $(MCS) -d -n .SUNW_dof $@ > /dev/null 2>&1
1299 $(AR) -ts $@ > /dev/null
1302 $(LIBCBASE)/crt/_rtbootld.s: $(LIBCBASE)/crt/_rtboot.s $(LIBCBASE)/crt/_rtld.c
1303 $(CC) $(CPPFLAGS) $(CTF_FLAGS) -O -S $(C_PICFLAGS) \
1304 $(LIBCBASE)/crt/_rtld.c -o $(LIBCBASE)/crt/_rtld.s
1305 $(CAT) $(LIBCBASE)/crt/_rtboot.s $(LIBCBASE)/crt/_rtld.s > $@
1306 $(RM) $(LIBCBASE)/crt/_rtld.s
1308 # partially built from C source
1309 pics/_rtbootld.o: $(LIBCBASE)/crt/_rtbootld.s
1310 $(AS) $(ASFLAGS) $(LIBCBASE)/crt/_rtbootld.s -o $@
1314 _lwp_mutex_unlock.o \
1321 $(ASSYMDEP_OBJS:%=pics/%) := CPPFLAGS += -I.
1323 $(ASSYMDEP_OBJS:%=pics/%): assym.h
1325 # assym.h build rules
1327 GENASSYM_C = $(LIBCDIR)/$(MACH)/genassym.c
1329 genassym: $(GENASSYM_C)
1330 $(NATIVECC) $(NATIVE_CFLAGS) -I$(LIBCBASE)/inc -I$(LIBCDIR)/inc \
1331 -D__EXTENSIONS__ $(CPPFLAGS.native) -o $@ $(GENASSYM_C)
1333 OFFSETS = $(LIBCDIR)/$(MACH)/offsets.in
1335 assym.h: $(OFFSETS) genassym
1336 $(OFFSETS_CREATE) <$(OFFSETS) >$@
1339 # derived C source and related explicit dependencies
1340 $(LIBCDIR)/port/gen/errlst.c + \
1341 $(LIBCDIR)/port/gen/new_list.c: $(LIBCDIR)/port/gen/errlist $(LIBCDIR)/port/gen/errlist.awk
1342 cd $(LIBCDIR)/port/gen; pwd; $(AWK) -f errlist.awk < errlist
1344 pics/errlst.o: $(LIBCDIR)/port/gen/errlst.c
1346 pics/new_list.o: $(LIBCDIR)/port/gen/new_list.c