pub/scm/linux/kernel/git/mcgrof/linker-tables.git  about / heads / tags
mirror of
$ git log --pretty=format:'%h %s (%cs)%d'
86ec117 tables.h: add assembler versions (2016-06-29)
	(HEAD -> master)
63cea6e asm-generic/sections.h: extend assembler push_section_type() (2016-06-29)
81c4710 asm-generic/sections.h: add assembler version of push_section_type() (2016-06-29)
31e11e2 x86: add architecture enabled ps_shr() (2016-06-29)
56b6b43 ranges.h: add push_section_rng() to be used on asm volatile() (2016-06-29)
b9dce6b tables.h: add push_section_tbl() for asm volatile calls (2016-06-29)
65b85f7 asm-generic: add push_section_type() to be used on asm volatile() code (2016-06-29)
c16aefb tables.h: enable use of SECTION_TBL() on asm code (2016-06-29)
923a4eb synth: add partially static shift right demo (2016-06-29)
3adf023 ranges.h: add asm version of DECLARE_SECTION_RANGE() (2016-06-27)

$ git cat-file blob HEAD:README



Simulated boots

This programs simulates boot in on both bare metal and xen.
The goal of the code is to illustrate an issue of dead code
and how we can fix this.

Emulate bare metal boot:


Emulate xen boot:

./main -x

Section ranges and tables

There are standard ELF sections and over time Linux has defined a series of
custom ELF sections which are now de facto Linux sections. Together we refer
to these as Linux ELF sections. History shows there are two forms in which Linux
sections can be used for:

 o Section ranges - typically used for grouping a set of executable functions
 o Section tables - typically used for grouping a set of data structures

In order to help build concrete and clean, separate semantics for both, we
provide separate helpers for code to declare and use them.  There is also
a common set of helpers which both make use of, this is provided in
include/linux/sections.h -- the file consists of of all known Linux ELF
sections, a few helpers used for alignment, size, and building section names.
Two common set of helpers are used to help distinguish whether or not a
particular section range or section table is const or not:

#define DECLARE_LINUX_SECTION(type, name)				\
	extern type name[], name##__end[];

#define DECLARE_LINUX_SECTION_RO(type, name)				\
	extern const type name[], name##__end[];

Linux section ranges only use DECLARE_LINUX_SECTION_RO(). So the only thing
else needed is to be able to specify the actual Linux section associated with
the range. You use DECLARE_SECTION_RANGE() to declare section ranges with an
associated name on header files, this lets other code access it. You define
section ranges in code with DEFINE_SECTION_RANGE() which associates the
specific section range with a Linux section.

Linux section tables can be of const or non-const type as such can use either
are provided to help associate Linux section tables to specific sections with
an appropriate common helper declaration.

The two main section types, section ranges, section tables, then are referred
to with the following macros for declaring each on their respective header
files so others can refer to them; and defining them in the respective code
that defines its proper use:

   Section type     |ELF name|    Declared on header   |    Defined in code

There are only two declarations for linker tables, which would be used in
header files:

  o DECLARE_LINKTABLE()		for data
  o DECLARE_LINKTABLE_RO()	for read-only data

The tables have a series of definitions (DEFINE_LINKTABLE_*()) given to help
with setup for the different supported Linux sections used. The definitions
would be used in the code defining the use of tables -- the actual

The definitions currently supported for tables are:

Linux section    |    const-or-not  |  Definition
.data            |    non-const     |  DEFINE_LINKTABLE()
.text            |    const         |  DEFINE_LINKTABLE_TEXT()
.init            |    const         |  DEFINE_LINKTABLE_INIT()       |    non-const     |  DEFINE_LINKTABLE_INIT_DATA()
.rodata          |    const         |  DEFINE_LINKTABLE_RO()

x86 bzimage parser

An x86 image parser has been added to aid the integration requirements
of using futher boot_params for dead code concerns. Example usage:

./parse-bzimage ~/linux/arch/x86/boot/bzImage 
kernel: /home/mcgrof/linux/arch/x86/boot/bzImage
kernel size:    5668000 bytes
Going to parse kernel...

Xen Expects:    0x53726448
Qemu Expects:   0x53726448
On image:       0x53726448

bzImage protocol Version: v2.13
Xen hdr->version:       525
Qemu protocol:          525
Qemu VERSION(2,8):      520

Boot protocol 2.07:     0x0207  (supports hardware_subarch)
Boot protocol 2.08:     0x0208
Boot protocol 2.09:     0x0209
Boot protocol 2.10:     0x020a
Boot protocol 2.11:     0x020b
Boot protocol 2.12:     0x020c
Boot protocol 2.13:     0x020d

Member                                  Offset  Expected        Match
setup_header->loadflags                 0x0211  0x0211          YES
setup_header->hardware_subarch          0x023c
setup_header->hardware_subarch_data     0x0240


 o Finish checking LTO_REFERENCE_INITCALL() is indeed needed. I've aksed [0].
   so now just waiting on that discussion to complete. If its not needed,
   rip it out of the Linux kernel and then from here.


Table solution history

The init table solution implemented here is a combination of how the
Linux IOMMU init framework was implemented *and* how GPXE sorts its
own init work.

Table sorting

The Linux IOMMU solution gives us dependency annotations,
so one set of routines will not run until its dependency runs. The
sorting for this takes place with a C routine which ultimately
memmove()'s the routines in order.

The sorting done by the GPXE solution is all done by the linker
by the good 'ol SORT() through in the object's linker script.

We want to enable different subsystems to implement their own
table solutions and this can mean having different init structure
members, that is how the gpxe solution works. Sorting is done automatically
for you through linker at build time. The sorting through the IOMMU init
solution works using the actual specific structure for the subsystem
used and the semantics for the sorting must be clearly documented and
defined. For instance the original IOMMU init solution requires only
one init solution to have a NULL set for its depends callback. For
our mockup x86 init solution we are allowing both "depends" and
"detect" to be NULL. For changes to how our sorting implementation
was modified refer to commit 9e01858bbc74a11 ("init: enable support
for no depends() callback). The sorting for routines that do not have
a "depends" callback set would happen through the order table level
used, a la gpxe solution. When the order levels are the same we rely
on order of linking -- for instance: placement of the routines in the
C file, and at the file level based on order in the Makefile.

Furthermore, upon initialization the mockup x86 init solution relies
on the subarchitecture to skip routines which are not supported or
intended for its subarchitecture.

It might be possible to share a common C sort routine for all tables
but the first challenge is we'd likely be constraining our init structures.
For instance since the current sorting looks for an init routine's "depends"
callback, that callback will be placed in a specific location as part of the
structure. In order to share a sort we'd have to enforce a common set of
table structures for at least the sorting semantics, for instance this
could perhaps be accomplished by placing all relevant members relevant to
sorting semantics in the beginning of the structure. The next challenge
has to do with size, given that we move structures around with memmove()
and this is done depending on the size of the init structure, and that
is up to each subsystem to define. This could be resolved by fixating the
size of all table init structures.

For now each subsystem must then define its own sorting scheme. A sorting
algorithm is only necessary if the linker script sorting does not suffice
for the semantics of the subsystem.

File mapping upstream

In case this project maintains a matching with upstream this project strives
to maintain a one to one direct mapping as things are or we hope would
be on upstream Linux.

# heads (aka `branches'):
$ git for-each-ref --sort=-creatordate refs/heads \
	--format='%(HEAD) %(refname:short) %(subject) (%(creatordate:short))'
* master       tables.h: add assembler versions (2016-06-29)
  20160603-dev-v3 sections.h: add generic section declaration (2016-06-03)
  20160525-dev-v3 compiler.h, kprobes.h: add missing header files (2016-05-25)

# tags:
$ git for-each-ref --sort=-creatordate refs/tags \
	--format='%(refname:short) %(subject) (%(creatordate:short))'
# no tags, yet...

# associated public inboxes:
# (number on the left is used for dev purposes)
         34 xen-devel
         34 linux-arch
         34 platform-driver-x86
         34 sparclinux
          4 lkml
          3 qemu-devel
          3 u-boot
          2 linux-media
          2 dpdk-dev
          2 linux-trace-devel
          2 linux-api
          2 linux-fpga
          2 openembedded-core
          2 cluster-devel
          1 linux-samsung-soc
          1 linux-fscrypt
          1 linux-wireless
          1 linux-mtd
          1 cocci
          1 linux-block
          1 linux-riscv
          1 linux-nvme
          1 linux-xfs
          1 live-patching
          1 bpf
          1 linux-nfs
          1 linux-mediatek
          1 linux-crypto
          1 linux-efi
          1 linux-acpi
          1 netfilter-devel
          1 linux-integrity
          1 linux-fsdevel
          1 linux-edac
          1 linux-cifs
          1 linux-devicetree
          1 linux-arm-msm
          1 linux-amlogic
          1 linux-erofs
          1 linux-mm
          1 linux-nvdimm
          1 linux-iommu
          1 netdev
          1 stable
          1 linux-snps-arc
          1 linux-mips
          1 fstests
          1 linux-pm
          1 linux-hwmon
          1 linux-rtc
          1 linux-input
          1 alsa-devel
          1 linux-scsi
          1 linux-btrfs
          1 linux-arm-kernel
          1 kvmarm
          1 driverdev-devel
          1 linux-usb
          1 linux-renesas-soc
          1 linux-kselftest
          1 selinux
          1 kernel-hardening
          1 linux-clk
          1 linux-iio
          1 linux-gpio
          1 dmaengine
          1 linux-rdma
          1 linux-next
          1 linux-parisc
          1 linux-ext4
          1 linux-leds
          1 linux-security-module
          1 linux-pci
          1 linux-f2fs-devel
          1 linuxppc-dev
          1 kvm
          1 linux-modules
          1 kernelnewbies
          1 linux-rt-users
          1 linux-bluetooth
          1 linux-sgx
          1 linux-ide
          1 linux-serial
          1 linux-watchdog
          1 linux-hyperv
          1 workflows
          1 rcu
          1 linux-m68k
          1 linux-i3c
          1 util-linux
          1 linux-spdx
          1 linux-wpan
          1 ksummit-discuss
          1 wireguard
          1 backports
          1 io-uring
          1 linux-kernel-mentees
          1 linux-doc
          1 git
          1 linux-csky
          1 linux-man
          1 linux-mmc
          1 amd-gfx
          1 dri-devel
          1 intel-gfx
          1 tpmdd-devel
          1 linux-unionfs
          1 linux-firmware
          1 cip-dev
          1 linux-omap
          1 linux-audit
          1 linux-spi
          1 linux-i2c
          1 linux-remoteproc
          1 linux-dash
          1 linux-bcache
          1 linux-sparse
          1 mm-commits
          1 linux-pwm
          1 linux-tegra
          1 lttng-dev
          1 virtualization
          1 linux-kbuild
          1 ceph-devel
          1 linux-can
          1 containers
          1 linux-rockchip
          1 linux-raid
          1 xdp-newbies
          1 phone-devel
          1 openbmc
          1 linux-hardening
          1 dash
          1 dm-devel
          1 keyrings
          1 linux-fbdev
          1 linux-sctp
          1 linux-cxl
          1 linux-perf-users
          1 target-devel
          1 lustre-devel
          1 linux-sh
          1 soc
          1 ocfs2-devel
          1 rust-for-linux
          1 ath10k
          1 ath11k
          1 nouveau
          1 linux-phy
          1 linux-s390
          1 kernel-janitors
          1 linux-staging
          1 linux-sunxi
          1 mptcp
          1 linux-coco
          1 regressions
          1 ksummit
          1 b43-dev
          1 nvdimm
          1 linux-nfc
          1 linux-bcachefs
          1 ath9k-devel
          1 buildroot
          1 ntfs3
          1 llvm
          1 fio
          1 iwd
          1 ell
          1 ofono
          1 ltp
          1 yocto
          1 yocto-meta-freescale
          1 yocto-toaster
          1 yocto-meta-arm
          1 yocto-docs
          1 openembedded-devel
          1 bitbake-devel
          1 linux-patches
          1 yocto-meta-virtualization
          1 chrome-platform
          1 ntb
          1 yocto-meta-ti
          1 yocto-meta-arago
          1 outreachy
          1 xenomai
          1 damon
          1 asahi
          1 openrisc
          1 intel-wired-lan
          1 kexec
          1 loongarch
          1 imx
          1 ath12k
          1 b4-sent
          1 linux-trace-kernel
          1 oe-linux-nfc
          1 oe-kbuild-all
          1 oe-chipsec
          1 batman
          1 intel-xe
          1 linux-um
          1 virtio-dev
          1 virtio-comment
          1 v9fs
          1 ecryptfs
          1 poky
          1 qemu-riscv
          1 linux-ia64
          1 grub-devel
          1 kbd
          1 autofs
          1 cpufreq
          1 dccp
          1 cgroups
          1 devicetree-spec
          1 devicetree-compiler
          1 initramfs
          1 kvm-ppc
          1 hail-devel
          1 kvm-ia64
          1 linux-8086
          1 kernel-testers
          1 linux-alpha
          1 linux-btrace
          1 linux-embedded
          1 linux-hams
          1 linux-hexagon
          1 linux-hotplug
          1 linux-laptop
          1 linux-sound
          1 trinity
          1 reiserfs-devel
          1 linux-metag
          1 linux-x25
          1 linux-nilfs
          1 lvs-devel
          1 netfilter
          1 linux-oxnas
          1 u-boot-amlogic
          1 lm-sensors
          1 lvm-devel
          1 acpica-devel
          1 perfbook
          1 virtio-fs
          1 smatch
          1 ../../../../../../../fuego
          1 ../../../../../../../wireless-regdb
          1 ../../../../../../../igt-dev
          1 ../../../../../../../powertop

git clone