mirror of
https://github.com/opnsense/src.git
synced 2026-06-18 13:10:00 -04:00
Eliminate the use of commons in the kernel and modules,
simplifying the module linking process and eliminating the risks
associated with doubly-defined variables.
Cases where commons were legitimately used (detection of
compiled-in subsystems) have been converted to use sysinits, and
any new code should use this or an equivalent practice as a
matter of course.
Modules can override this behaviour by substituting -fno-common
out of ${CFLAGS} in cases where commons are necessary
(eg. third-party object modules). Commons will be resolved and
allocated space when the kld is linked as part of the module
build process, so they will not pose a risk to the kernel or
other modules.
Provide a mechanism for controlling the export of symbols from
the module namespace. The EXPORT_SYMS variable may be set in the
Makefile to NO (export no symbols), a list of symbols to export,
or the name of a file containing a newline-seperated list of
symbols to be exported. Non-exported symbols are converted to
local symbols. If EXPORT_SYMS is not set, all global symbols are
currently exported. This behaviour is expected to change (to
exporting no symbols) once modules have been converted.
Reviewed by: peter (in principle)
Obtained from: green (kmod_syms.awk)
This commit is contained in:
parent
9539704639
commit
0b3178a45c
4 changed files with 58 additions and 4 deletions
|
|
@ -76,7 +76,7 @@ assym.s: $S/kern/genassym.sh genassym.o
|
|||
NM=${NM} OBJFORMAT=elf sh $S/kern/genassym.sh genassym.o > ${.TARGET}
|
||||
|
||||
genassym.o: $S/$M/$M/genassym.c
|
||||
${CC} -c ${CFLAGS} $S/$M/$M/genassym.c
|
||||
${CC} -c ${CFLAGS:N-fno-common} $S/$M/$M/genassym.c
|
||||
|
||||
${SYSTEM_OBJS} genassym.o vers.o: opt_global.h
|
||||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ INCLUDES+= -I/usr/include
|
|||
.endif
|
||||
|
||||
COPTS= ${INCLUDES} ${IDENT} -D_KERNEL -ffreestanding -include opt_global.h
|
||||
CFLAGS= ${COPTFLAGS} ${CWARNFLAGS} ${DEBUG} ${COPTS}
|
||||
CFLAGS= ${COPTFLAGS} ${CWARNFLAGS} ${DEBUG} ${COPTS} -fno-common
|
||||
|
||||
# XXX LOCORE means "don't declare C stuff" not "for locore.s".
|
||||
ASM_CFLAGS= -x assembler-with-cpp -DLOCORE ${CFLAGS}
|
||||
|
|
@ -76,7 +76,7 @@ SYSTEM_SFILES= $S/$M/$M/locore.s
|
|||
SYSTEM_DEP= Makefile ${SYSTEM_OBJS}
|
||||
SYSTEM_OBJS= locore.o vnode_if.o ${OBJS} hints.o env.o config.o hack.So
|
||||
SYSTEM_LD= @${LD} ${FMT} -Bdynamic -T $S/conf/ldscript.$M \
|
||||
-export-dynamic -dynamic-linker /red/herring \
|
||||
-warn-common -export-dynamic -dynamic-linker /red/herring \
|
||||
-o ${.TARGET} -X ${SYSTEM_OBJS} vers.o
|
||||
SYSTEM_LD_TAIL= @${OBJCOPY} --strip-symbol gcc2_compiled. ${.TARGET} ; \
|
||||
${SIZE} ${FMT} ${.TARGET} ; chmod 755 ${.TARGET}
|
||||
|
|
|
|||
|
|
@ -51,6 +51,11 @@
|
|||
# MFILES Optionally a list of interfaces used by the module.
|
||||
# This file contains a default list of interfaces.
|
||||
#
|
||||
# EXPORT_SYMS A list of symbols that should be exported from the module,
|
||||
# or the name of a file containing a list of symbols, or NO
|
||||
# to export no symbols. If missing, all global symbols are
|
||||
# exported.
|
||||
#
|
||||
# +++ targets +++
|
||||
#
|
||||
# distribute:
|
||||
|
|
@ -119,6 +124,11 @@ CFLAGS+= -I${DESTDIR}/usr/include
|
|||
CFLAGS+= -I@/../include -I${DESTDIR}/usr/include
|
||||
.endif # @
|
||||
|
||||
# Disallow common variables, and if we end up with commons from
|
||||
# somewhere unexpected, allocate storage for them in the module itself.
|
||||
CFLAGS+= -fno-common
|
||||
LDFLAGS+= -d -warn-common
|
||||
|
||||
CFLAGS+= ${DEBUG_FLAGS}
|
||||
|
||||
.if ${OBJFORMAT} == elf
|
||||
|
|
@ -143,8 +153,25 @@ ${PROG}: ${FULLPROG}
|
|||
${FULLPROG}: ${KMOD}.kld
|
||||
${LD} -Bshareable ${LDFLAGS} -o ${.TARGET} ${KMOD}.kld
|
||||
|
||||
.if defined(EXPORT_SYMS)
|
||||
CLEANFILES+= ${.OBJDIR}/export_syms
|
||||
.endif
|
||||
|
||||
${KMOD}.kld: ${OBJS}
|
||||
${LD} ${LDFLAGS} -r -o ${.TARGET} ${OBJS}
|
||||
${LD} ${LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
|
||||
.if defined(EXPORT_SYMS)
|
||||
.if ${EXPORT_SYMS} == NO
|
||||
touch ${.OBJDIR}/export_syms
|
||||
.elif !exists(${.CURDIR}/${EXPORT_SYMS})
|
||||
echo ${EXPORT_SYMS} > ${.OBJDIR}/export_syms
|
||||
.else
|
||||
grep -v '^#' < ${EXPORT_SYMS} > ${.OBJDIR}/export_syms
|
||||
.endif
|
||||
awk -f ${SYSDIR}/conf/kmod_syms.awk ${.TARGET} \
|
||||
${.OBJDIR}/export_syms | \
|
||||
xargs -t -J% ${OBJCOPY} % ${.TARGET}
|
||||
.endif
|
||||
|
||||
|
||||
.if !defined(NOMAN)
|
||||
.if 0
|
||||
|
|
|
|||
27
sys/conf/kmod_syms.awk
Normal file
27
sys/conf/kmod_syms.awk
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
# $FreeBSD$
|
||||
|
||||
# Read global symbols from object file.
|
||||
BEGIN {
|
||||
while ("nm -g " ARGV[1] | getline) {
|
||||
if (match($0, /^[^[:space:]]+ [^AU] (.*)$/)) {
|
||||
syms[$3] = $2
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# De-list symbols from the export list.
|
||||
// {
|
||||
if (ARGIND == 1)
|
||||
nextfile
|
||||
delete syms[$0]
|
||||
}
|
||||
|
||||
# Strip commons, make everything else local.
|
||||
END {
|
||||
for (member in syms) {
|
||||
if (syms[member] == "C")
|
||||
print "-N" member
|
||||
else
|
||||
print "-L" member
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue