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