xref: /freebsd-12.1/gnu/lib/libgcc/Makefile (revision 14c3b02e)
1# $FreeBSD$
2
3PACKAGE=	clibs
4GCCDIR=	${.CURDIR}/../../../contrib/gcc
5GCCLIB=	${.CURDIR}/../../../contrib/gcclibs
6CCDIR=	${.CURDIR}/../../usr.bin/cc
7COMPILERRTDIR=	${.CURDIR}/../../../contrib/compiler-rt
8UNWINDINCDIR=	${.CURDIR}/../../../contrib/llvm/projects/libunwind/include
9UNWINDSRCDIR=	${.CURDIR}/../../../contrib/llvm/projects/libunwind/src
10
11SHLIB_NAME=	libgcc_s.so.1
12SHLIBDIR?=	/lib
13
14.include <src.opts.mk>
15#
16# libgcc is linked in last and thus cannot depend on ssp symbols coming
17# from earlier libraries. Disable stack protection for this library.
18#
19MK_SSP=	no
20
21.include "${CCDIR}/Makefile.tgt"
22.include "${CCDIR}/cc_tools/Makefile.hdrs"
23
24.if ${TARGET_CPUARCH} == "arm"
25CFLAGS+=	-DTARGET_ARM_EABI
26.endif
27
28.PATH: ${GCCDIR}/config/${GCC_CPU} ${GCCDIR}/config ${GCCDIR}
29
30CFLAGS+=	-DIN_GCC -DIN_LIBGCC2 -D__GCC_FLOAT_NOT_NEEDED \
31		-DHAVE_GTHR_DEFAULT \
32		-I${GCCLIB}/include \
33		-I${GCCDIR}/config -I${GCCDIR} -I.
34
35LDFLAGS+=	-nodefaultlibs
36LIBADD+=	c
37
38SOBJS=		# added to below in various ways depending on TARGET_CPUARCH
39
40#---------------------------------------------------------------------------
41#
42# Library members defined in libgcc2.c.
43# When upgrading GCC, obtain the following list from mklibgcc.in
44#
45LIB2FUNCS= _muldi3 _negdi2 _lshrdi3 _ashldi3 _ashrdi3 \
46	_cmpdi2 _ucmpdi2 \
47	_enable_execute_stack _trampoline __main _absvsi2 _absvdi2 _addvsi3 \
48	_addvdi3 _subvsi3 _subvdi3 _mulvsi3 _mulvdi3 _negvsi2 _negvdi2 _ctors \
49	_ffssi2 _ffsdi2 _clz _clzsi2 _clzdi2 _ctzsi2 _ctzdi2 _popcount_tab \
50	_popcountsi2 _popcountdi2 _paritysi2 _paritydi2 _powisf2 _powidf2 \
51	_powixf2 _powitf2 _mulsc3 _muldc3 _mulxc3 _multc3 _divsc3 _divdc3 \
52	_divxc3 _divtc3 _bswapsi2 _bswapdi2
53.if ${COMPILER_TYPE} != "clang" || ${TARGET_CPUARCH} != "arm"
54LIB2FUNCS+= _clear_cache
55.endif
56
57# The floating-point conversion routines that involve a single-word integer.
58.for mode in sf df xf
59LIB2FUNCS+= _fixuns${mode}si
60.endfor
61
62# Likewise double-word routines.
63.if ${TARGET_CPUARCH} != "aarch64" && ${TARGET_CPUARCH} != "arm" && \
64    ${TARGET_CPUARCH} != "riscv64"
65# These are implemented in an ARM specific file but will not be filtered out.
66# RISCVTODO: can't compile
67.for mode in sf df xf tf
68LIB2FUNCS+= _fix${mode}di _fixuns${mode}di
69LIB2FUNCS+= _floatdi${mode} _floatundi${mode}
70.endfor
71.endif
72
73LIB2ADD = $(LIB2FUNCS_EXTRA)
74LIB2ADD_ST = $(LIB2FUNCS_STATIC_EXTRA)
75
76# Additional sources to handle exceptions; overridden by targets as needed.
77.if ${MK_LLVM_LIBUNWIND} != "no"
78
79.PATH: ${COMPILERRTDIR}/lib/builtins
80.PATH: ${UNWINDSRCDIR}
81LIB2ADDEH = gcc_personality_v0.c \
82	int_util.c \
83	Unwind-EHABI.cpp \
84	Unwind-sjlj.c \
85	UnwindLevel1-gcc-ext.c \
86	UnwindLevel1.c \
87	UnwindRegistersRestore.S \
88	UnwindRegistersSave.S \
89	libunwind.cpp
90
91CFLAGS+=	-I${UNWINDINCDIR} -I${.CURDIR} -D_LIBUNWIND_IS_NATIVE_ONLY
92.if empty(CXXFLAGS:M-std=*)
93CXXFLAGS+=	-std=c++11
94.endif
95CXXFLAGS+=	-fno-rtti
96STATIC_CXXFLAGS+= -fvisibility=hidden -fPIC
97.if ${MK_DIRDEPS_BUILD} == "yes"
98# Avoid dependency on lib/libc++
99CFLAGS+=	-I${SRCTOP}/contrib/libc++/include
100.endif
101
102.else # MK_LLVM_LIBUNWIND
103
104#
105# Prevent the potential unwind.h from gcc (generated)
106# to be in the include path before the one from llvm unwind
107#
108CFLAGS+=	-I${CCDIR}/cc_tools
109
110.if ${TARGET_CPUARCH} == "arm"
111LIB2ADDEH =	unwind-arm.c libunwind-arm.S pr-support.c unwind-c.c
112.else
113LIB2ADDEH = unwind-dw2.c unwind-dw2-fde-glibc.c unwind-sjlj.c gthr-gnat.c \
114	unwind-c.c
115.endif
116
117.endif # MK_LLVM_LIBUNWIND
118
119LIB2ADDEHSTATIC = $(LIB2ADDEH)
120LIB2ADDEHSHARED = $(LIB2ADDEH)
121
122# List of extra C and assembler files to add to static and shared libgcc2.
123# Assembler files should have names ending in `.asm'.
124LIB2FUNCS_EXTRA =
125
126# List of extra C and assembler files to add to static libgcc2.
127# Assembler files should have names ending in `.asm'.
128LIB2FUNCS_STATIC_EXTRA =
129
130# Defined in libgcc2.c, included only in the static library.
131# KAN: Excluded _sf_to_tf and _df_to_tf as TPBIT_FUNCS are not
132# built on any of our platforms.
133LIB2FUNCS_ST = _eprintf __gcc_bcmp
134
135FPBIT_FUNCS = _pack_sf _unpack_sf _addsub_sf _mul_sf _div_sf \
136    _fpcmp_parts_sf _compare_sf _eq_sf _ne_sf _gt_sf _ge_sf \
137    _lt_sf _le_sf _unord_sf _si_to_sf _sf_to_si _negate_sf _make_sf \
138    _sf_to_df _thenan_sf _sf_to_usi _usi_to_sf
139
140DPBIT_FUNCS = _pack_df _unpack_df _addsub_df _mul_df _div_df \
141    _fpcmp_parts_df _compare_df _eq_df _ne_df _gt_df _ge_df \
142    _lt_df _le_df _unord_df _si_to_df _df_to_si _negate_df _make_df \
143    _df_to_sf _thenan_df _df_to_usi _usi_to_df
144
145TPBIT_FUNCS = _pack_tf _unpack_tf _addsub_tf _mul_tf _div_tf \
146    _fpcmp_parts_tf _compare_tf _eq_tf _ne_tf _gt_tf _ge_tf \
147    _lt_tf _le_tf _unord_tf _si_to_tf _tf_to_si _negate_tf _make_tf \
148    _tf_to_df _tf_to_sf _thenan_tf _tf_to_usi _usi_to_tf
149
150# These might cause a divide overflow trap and so are compiled with
151# unwinder info.
152LIB2_DIVMOD_FUNCS = _divdi3 _moddi3 _udivdi3 _umoddi3 _udiv_w_sdiv _udivmoddi4
153
154#-----------------------------------------------------------------------
155#
156#	Platform specific bits.
157#	When upgrading GCC, get the following definitions from config/<cpu>/t-*
158#
159.if ${TARGET_CPUARCH} == "arm"
160#	from config/arm/t-strongarm-elf
161CFLAGS+=	-Dinhibit_libc -fno-inline
162CFLAGS.clang+=	-fheinous-gnu-extensions
163
164LIB1ASMSRC =	lib1funcs.asm
165LIB1ASMFUNCS =  _dvmd_tls _bb_init_func
166# Some compilers generate __aeabi_ functions libgcc_s is missing
167LIBADD+=	compiler_rt
168.endif
169
170.if ${TARGET_CPUARCH} == mips
171LIB2FUNCS_EXTRA = floatunsidf.c floatunsisf.c
172# ABIs other than o32 need this
173.if ${TARGET_ARCH} != "mips" && ${TARGET_ARCH} != "mipsel"
174LIB2FUNCS_EXTRA+= floatdidf.c fixunsdfsi.c
175LIB2FUNCS_EXTRA+= floatdisf.c floatundidf.c
176LIB2FUNCS_EXTRA+= fixsfdi.c floatundisf.c
177LIB2FUNCS_EXTRA+= fixdfdi.c fixunssfsi.c
178.endif
179.endif
180
181.if ${TARGET_ARCH} == "powerpc"
182#	from config/rs6000/t-ppccomm
183LIB2FUNCS_EXTRA = tramp.asm
184LIB2FUNCS_STATIC_EXTRA = eabi.asm
185.endif
186
187.if ${TARGET_ARCH} == "powerpc64"
188#	from config/rs6000/t-ppccomm
189LIB2FUNCS_EXTRA = tramp.asm
190.endif
191
192.if ${TARGET_CPUARCH} == "sparc64"
193#	from config/sparc/t-elf
194LIB1ASMSRC =   lb1spc.asm
195LIB1ASMFUNCS = _mulsi3 _divsi3 _modsi3
196.endif
197
198#-----------------------------------------------------------------------
199
200# Remove any objects from LIB2FUNCS and LIB2_DIVMOD_FUNCS that are
201# defined as optimized assembly code in LIB1ASMFUNCS.
202.if defined(LIB1ASMFUNCS)
203.for sym in ${LIB1ASMFUNCS}
204LIB2FUNCS:=	${LIB2FUNCS:S/${sym}//g}
205LIB2_DIVMOD_FUNCS:= ${LIB2_DIVMOD_FUNCS:S/${sym}//g}
206.endfor
207.endif
208
209COMMONHDRS=	tm.h tconfig.h options.h gthr-default.h
210.if ${MK_LLVM_LIBUNWIND} != "no"
211# unwind.h is a generated file when MK_LLVM_LIBUNWIND == "no", and a stale
212# copy may be left behind in OBJDIR when switching, so remove it explicitly.
213beforebuild:
214	@rm -f ${.OBJDIR}/unwind.h
215.else
216COMMONHDRS+=	unwind.h
217.endif
218
219#-----------------------------------------------------------------------
220#
221# Helpful shortcuts for compiler invocations.
222#
223HIDE =  -fvisibility=hidden -DHIDE_EXPORTS
224CC_T =	${CC} -c ${CFLAGS} ${HIDE} -fPIC
225CC_P =	${CC} -c ${CFLAGS} ${HIDE} -p -fPIC
226CC_S =	${CC} -c ${CFLAGS} ${SHARED_CFLAGS} ${PICFLAG} -DSHARED
227
228#-----------------------------------------------------------------------
229#
230# Functions from libgcc2.c
231#
232STD_CFLAGS =
233DIV_CFLAGS =	-fexceptions -fnon-call-exceptions
234
235STD_FUNCS =	${LIB2FUNCS}
236DIV_FUNCS =	${LIB2_DIVMOD_FUNCS}
237
238STD_CFILE =	libgcc2.c
239DIV_CFILE =	libgcc2.c
240
241OBJ_GRPS =	STD DIV
242
243#-----------------------------------------------------------------------
244#
245# Floating point emulation functions
246#
247.if ${TARGET_CPUARCH} == "armNOT_YET" || \
248    ${TARGET_CPUARCH} == "powerpc" || ${TARGET_CPUARCH} == "sparc64"
249
250FPBIT_CFLAGS =	-DFINE_GRAINED_LIBRARIES -DFLOAT
251DPBIT_CFLAGS =	-DFINE_GRAINED_LIBRARIES
252
253FPBIT_CFILE =	config/fp-bit.c
254DPBIT_CFILE =	config/fp-bit.c
255
256OBJ_GRPS +=	FPBIT DPBIT
257.endif
258
259#-----------------------------------------------------------------------
260#
261# Generic build rules for object groups defined above
262#
263.for T in ${OBJ_GRPS}
264${T}_OBJS_T =	${${T}_FUNCS:S/$/.o/}
265${T}_OBJS_P =	${${T}_FUNCS:S/$/.po/}
266${T}_OBJS_S =	${${T}_FUNCS:S/$/.pico/}
267SOBJS +=	${${T}_FUNCS:S/$/.pico/}
268
269${${T}_OBJS_T}: ${${T}_CFILE} ${COMMONHDRS}
270	${CC_T} ${${T}_CFLAGS} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
271${${T}_OBJS_P}: ${${T}_CFILE} ${COMMONHDRS}
272	${CC_P} ${${T}_CFLAGS} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
273${${T}_OBJS_S}: ${${T}_CFILE} ${COMMONHDRS}
274	${CC_S} ${${T}_CFLAGS} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
275.endfor
276
277#-----------------------------------------------------------------------
278#
279# Extra objects coming from separate files
280#
281.if !empty(LIB2ADD)
282SOBJS +=	${LIB2ADD:R:S/$/.pico/}
283.endif
284
285#-----------------------------------------------------------------------
286#
287# Objects that should be in static library only.
288#
289SYMS_ST =	${LIB2FUNCS_ST}	${LIB2ADD_ST}
290STAT_OBJS_T = 	${SYMS_ST:S/$/.o/}
291STAT_OBJS_P = 	${SYMS_ST:S/$/.po/}
292STATICOBJS  =	${SYMS_ST:S/$/.o/}
293
294${STAT_OBJS_T}:	${STD_CFILE} ${COMMONHDRS}
295	${CC_T} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
296${STAT_OBJS_P}:	${STD_CFILE} ${COMMONHDRS}
297	${CC_P} -DL${.PREFIX} -o ${.TARGET} ${.ALLSRC:M*.c}
298
299#-----------------------------------------------------------------------
300#
301# Assembler files.
302#
303.if defined(LIB1ASMSRC)
304ASM_T =		${LIB1ASMFUNCS:S/$/.o/}
305ASM_P =		${LIB1ASMFUNCS:S/$/.po/}
306ASM_S =		${LIB1ASMFUNCS:S/$/.pico/}
307ASM_V =		${LIB1ASMFUNCS:S/$/.vis/}
308SOBJS +=	${LIB1ASMFUNCS:S/$/.pico/}
309
310${ASM_T}: ${LIB1ASMSRC} ${.PREFIX}.vis
311	${CC} -x assembler-with-cpp -c ${CFLAGS} -DL${.PREFIX} \
312	    -o ${.TARGET} -include ${.PREFIX}.vis ${.ALLSRC:N*.h:N*.vis}
313${ASM_P}: ${LIB1ASMSRC} ${.PREFIX}.vis
314	${CC} -x assembler-with-cpp -p -c ${CFLAGS} -DL${.PREFIX} \
315	    -o ${.TARGET} -include ${.PREFIX}.vis ${.ALLSRC:N*.h:N*.vis}
316${ASM_S}: ${LIB1ASMSRC}
317	${CC} -x assembler-with-cpp -c ${PICFLAG} ${CFLAGS} -DL${.PREFIX} \
318	    -o ${.TARGET} ${.ALLSRC:N*.h}
319${ASM_V}: ${LIB1ASMSRC}
320	${CC} -x assembler-with-cpp -c ${CFLAGS} -DL${.PREFIX} \
321	    -o ${.PREFIX}.vo ${.ALLSRC:N*.h}
322	( ${NM} -pg ${.PREFIX}.vo | \
323		awk 'NF == 3 && $$2 !~ /^[UN]$$/ { print "\t.hidden ", $$3 }'\
324	) > ${.TARGET}
325
326CLEANFILES += ${ASM_V} ${ASM_V:R:S/$/.vo/}
327.endif
328
329#-----------------------------------------------------------------------
330#
331# Exception handling / unwinding support.
332#
333EH_OBJS_T = ${LIB2ADDEHSTATIC:R:S/$/.o/}
334EH_OBJS_P = ${LIB2ADDEHSTATIC:R:S/$/.po/}
335EH_OBJS_S = ${LIB2ADDEHSHARED:R:S/$/.pico/}
336EH_CFLAGS = -fexceptions -D__GLIBC__=3 -DElfW=__ElfN
337.if ${TARGET_CPUARCH} != "riscv64"
338# RISCVTODO: unwinding support
339SOBJS    += ${EH_OBJS_S}
340.endif
341
342.for _src in ${LIB2ADDEHSTATIC:M*.c}
343${_src:R:S/$/.o/}: ${_src} ${COMMONHDRS}
344	${CC_T} ${EH_CFLAGS} -o ${.TARGET} ${.IMPSRC}
345${_src:R:S/$/.po/}: ${_src} ${COMMONHDRS}
346	${CC_P} ${EH_CFLAGS} -o ${.TARGET} ${.IMPSRC}
347.endfor
348.for _src in ${LIB2ADDEHSHARED:M*.c}
349${_src:R:S/$/.pico/}: ${_src} ${COMMONHDRS}
350	${CC_S} ${EH_CFLAGS} -o ${.TARGET} ${.IMPSRC}
351.endfor
352
353
354CLEANFILES += ${COMMONHDRS}
355CLEANFILES += cs-*.h option*
356
357#-----------------------------------------------------------------------
358#
359# Build symbol version map
360#
361SHLIB_MKMAP      = ${GCCDIR}/mkmap-symver.awk
362SHLIB_MKMAP_OPTS =
363SHLIB_MAPFILES   = ${GCCDIR}/libgcc-std.ver
364.if ${TARGET_CPUARCH} == "arm"
365SHLIB_MAPFILES  += ${GCCDIR}/config/arm/libgcc-bpabi.ver
366.endif
367VERSION_MAP      = libgcc.map
368
369libgcc.map: ${SHLIB_MKMAP} ${SHLIB_MAPFILES} ${SOBJS}
370	(  ${NM} -pg ${SOBJS};echo %% ; \
371	  cat ${SHLIB_MAPFILES} \
372	    | sed -e '/^[   ]*#/d' \
373	          -e 's/^%\(if\|else\|elif\|endif\|define\)/#\1/' \
374	    | ${CC} ${CFLAGS} -E -xassembler-with-cpp -; \
375	) | awk -f ${SHLIB_MKMAP} ${SHLIB_MKMAP_OPTS} > ${.TARGET}
376
377CLEANFILES +=	libgcc.map
378
379#-----------------------------------------------------------------------
380#
381# Build additional static libgcc_eh[_p].a libraries.
382#
383libgcc_eh.a:	${EH_OBJS_T}
384	@${ECHO} building static gcc_eh library
385	@rm -f ${.TARGET}
386	${AR} ${ARFLAGS} ${.TARGET} `lorder ${EH_OBJS_T} | tsort -q`
387	${RANLIB} ${RANLIBFLAGS} ${.TARGET}
388
389_LIBS+= libgcc_eh.a
390
391.if ${MK_PROFILE} != "no"
392libgcc_eh_p.a:	${EH_OBJS_P}
393	@${ECHO} building profiled gcc_eh library
394	@rm -f ${.TARGET}
395	${AR} ${ARFLAGS} ${.TARGET} `lorder ${EH_OBJS_P} | tsort -q`
396	${RANLIB} ${RANLIBFLAGS} ${.TARGET}
397
398_LIBS+= libgcc_eh_p.a
399.endif
400
401_libinstall: _lib-eh-install
402
403_lib-eh-install:
404.if ${MK_INSTALLLIB} != "no"
405	${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
406		${_INSTALLFLAGS} libgcc_eh.a ${DESTDIR}${LIBDIR}
407.endif
408.if ${MK_PROFILE} != "no"
409	${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
410		${_INSTALLFLAGS} libgcc_eh_p.a ${DESTDIR}${LIBDIR}
411.endif
412
413CLEANFILES+=	libgcc_eh.a libgcc_eh_p.a ${EH_OBJS_T} ${EH_OBJS_P}
414
415.include <bsd.lib.mk>
416
417.SUFFIXES: .vis .vo
418