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