Page MenuHomeFreeBSD

D17512.id48993.diff
No OneTemporary

D17512.id48993.diff

Index: sys/conf/kmod.mk
===================================================================
--- sys/conf/kmod.mk
+++ sys/conf/kmod.mk
@@ -242,7 +242,20 @@
.else
${FULLPROG}: ${OBJS}
.endif
+.if !defined(FIRMWS) && (${MACHINE_CPUARCH} == "i386")
+ # If the merge the first two we still get empty sets for each
+ # kernel module.
+ ${LD} -m ${LD_EMULATION} ${_LDFLAGS} -r \
+ -d -o ${.TARGET}.set_pad ${OBJS}
+ ${LD} -m ${LD_EMULATION} ${_LDFLAGS} -r \
+ -T ${SYSDIR}/conf/ldscript.set_pad \
+ -d -o ${.TARGET}.set_pad_apply ${.TARGET}.set_pad
+ ${LD} -m ${LD_EMULATION} ${_LDFLAGS} -r \
+ -T ${SYSDIR}/conf/ldscript.set_pad_apply \
+ -d -o ${.TARGET} ${.TARGET}.set_pad_apply
+.else
${LD} -m ${LD_EMULATION} ${_LDFLAGS} -r -d -o ${.TARGET} ${OBJS}
+.endif
.if ${MK_CTF} != "no"
${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
.endif
@@ -304,6 +317,14 @@
CLEANFILES+= ${PROG} ${KMOD}.kld ${OBJS}
+.if !defined(FIRMWS) && (${MACHINE_CPUARCH} == "i386")
+.if ${__KLD_SHARED} == yes
+CLEANFILES+= ${KMOD}.kld.set_pad ${KMOD}.kld.set_pad_apply
+.else
+CLEANFILES+= ${FULLPROG}.kld.set_pad ${FULLPROG}.kld.set_pad_apply
+.endif
+.endif
+
.if defined(DEBUG_FLAGS)
CLEANFILES+= ${FULLPROG} ${PROG}.debug
.endif
Index: sys/conf/ldscript.set_pad
===================================================================
--- /dev/null
+++ sys/conf/ldscript.set_pad
@@ -0,0 +1,57 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2018 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+/*
+ * This linker script (1/2) is used to determine whether a kernel module
+ * has a set_pcpu or a set_vnet section and record it in a new symbol.
+ * Neither the SIZEOF() not the output/inut section will create the section
+ * if it does not exist already.
+ * The new symbol is reduced to either 1 (if the section exist) or
+ * 0 (if the section does not exist). The value of the symbol will be
+ * used in the (2/2) linker script to enlarge (pad at the end) an already
+ * existing section by 1 byte.
+ * This is needed as the code generated on certain architectures for
+ * non-simple-types, e.g., an array can generate an absolute relocation
+ * on the edge (just outside) the section and thus will not be properly
+ * relocated. Adding the 1 byte pad to the end of the section will ensure
+ * that even absolute relocations of complex types will be inside the
+ * section, if they are the last object in there and hence relocation will
+ * work properly and avoid panics.
+ */
+___set_pcpu_pad = ABSOLUTE ( SIZEOF(set_pcpu) ? 1 : 0 ) ;
+SECTIONS
+{
+ set_pcpu : { *(set_pcpu) }
+}
+
+___set_vnet_pad = ABSOLUTE ( SIZEOF(set_vnet) ? 1 : 0 ) ;
+SECTIONS
+{
+ set_vnet : { *(set_vnet) }
+}
+/* end */
Index: sys/conf/ldscript.set_pad_apply
===================================================================
--- /dev/null
+++ sys/conf/ldscript.set_pad_apply
@@ -0,0 +1,56 @@
+/*-
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2018 Bjoern A. Zeeb
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+/*
+ * This linker script (2/2) possibly adds a 1 byte padding to the end of
+ * of a section should we have determined we need it.
+ * If the "_pad" zymbol is zero the section does not exist and the
+ * expression of . = . + 0; should not create the (empty) section
+ * (according to documentation). This may not always be true for all
+ * linkers or linker version. We try to do out best here we can to
+ * avoid creating unneeded empty sections.
+ * For further details see the description of the (1/2) link script.
+ */
+SECTIONS
+{
+ set_pcpu :
+ {
+ *(set_pcpu)
+ . = . + ABSOLUTE (___set_pcpu_pad) ;
+ }
+}
+
+SECTIONS
+{
+ set_vnet :
+ {
+ *(set_vnet)
+ . = . + ABSOLUTE (___set_vnet_pad) ;
+ }
+}
+/* end */

File Metadata

Mime Type
text/plain
Expires
Wed, Mar 18, 6:19 AM (18 h, 58 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
29844485
Default Alt Text
D17512.id48993.diff (6 KB)

Event Timeline