svn commit: r250306 - in stable/8/sys: net sys
John Baldwin
jhb at freebsd.org
Tue May 7 20:12:45 UTC 2013
On Tuesday, May 07, 2013 2:59:57 pm Dimitry Andric wrote:
> On 2013-05-07 01:13, Julian Elischer wrote:
> > On 5/6/13 12:59 PM, Dimitry Andric wrote:
> >> Author: dim
> >> Date: Mon May 6 19:59:13 2013
> >> New Revision: 250306
> >> URL: http://svnweb.freebsd.org/changeset/base/250306
> >>
> >> Log:
> >> MFC r215137:
> >>
> >> Revert r103230, which depended on ld preserving the __start_xxx and
> >> __stop_xxx symbols for custom sections, even when these were not
> >> referenced (at link time). This behaviour was changed again in binutils
> >> commit 0b8ed435c3fe8bd09a08c23920e65bfb03251221.
> >>
> >> This time, put the __GLOBL macro definition in cdefs.h, so it can be
> >> reused in a few other places where it will be needed.
> >
> > Is this stuff documented anywhere?
>
> If you mean the specifics of <sys/linker_set.h>, I don't think so. The
> documentation for the things that use it, are mostly in SYSINIT(9),
> DECLARE_MODULE(9) and module(9).
>
> In any case, the idea is that you tell the compiler and linker to add a
> few custom sections to the output, which contain metadata, for example
> to initialize a kernel module.
>
> Take the section headers of mpt.ko, for instance:
>
> Section Headers:
> [Nr] Name Type Addr Off Size ES Flg Lk Inf Al
> [ 0] NULL 00000000 000000 000000 00 0 0 0
> [ 1] .hash HASH 000000b4 0000b4 00038c 04 A 2 0 4
> [ 2] .dynsym DYNSYM 00000440 000440 000800 10 A 3 1 4
> [ 3] .dynstr STRTAB 00000c40 000c40 000792 00 A 0 0 1
> [ 4] .rel.dyn REL 000013d4 0013d4 004b80 08 A 2 0 4
> [ 5] .text PROGBITS 00005f60 005f60 01258a 00 AX 0 0 16
> [ 6] .rodata PROGBITS 000184f0 0184f0 00561d 00 A 0 0 16
> [ 7] set_modmetadata_set PROGBITS 0001db10 01db10 000054 00 A 0 0 4
> [ 8] set_sysinit_set PROGBITS 0001db64 01db64 000020 00 A 0 0 4
> [ 9] set_sysuninit_set PROGBITS 0001db84 01db84 000004 00 A 0 0 4
> [10] .dynamic DYNAMIC 0001e000 01e000 000078 08 WA 3 0 4
> [11] .got.plt PROGBITS 0001e078 01e078 00000c 04 WA 0 0 4
> [12] .data PROGBITS 0001e084 01e084 000478 00 WA 0 0 4
> [13] .bss NOBITS 0001e4fc 01e4fc 000310 00 WA 0 0 4
> [14] .comment PROGBITS 00000000 01e4fc 0001b3 01 MS 0 0 1
> [15] .SUNW_ctf PROGBITS 00000000 01e6b0 0065f7 00 0 0 4
> [16] .gnu_debuglink PROGBITS 00000000 024ca7 000014 00 0 0 1
> [17] .shstrtab STRTAB 00000000 024cbb 0000bd 00 0 0 1
> [18] .symtab SYMTAB 00000000 025098 0018d0 10 19 270 4
> [19] .strtab STRTAB 00000000 026968 001e9f 00 0 0 1
> Key to Flags:
> W (write), A (alloc), X (execute), M (merge), S (strings)
> I (info), L (link order), G (group), T (TLS), E (exclude), x (unknown)
> O (extra OS processing required) o (OS specific), p (processor specific)
>
> The 'set_*' sections are added by the linker_set macros, and are marked
> as used, so the compiler will not optimize them away.
>
> However, in some versions of binutils, the linker still optimizes them
> away, so we have to resort to inserting assembler directives to force it
> to keep them. This is what r103230 and r215137 were about.
You can use linker sets in userland as well. I used them in mfiutil and mptutil
to build nested command tables. I've also used linker sets to build lists of
unit tests in kernel modules.
--
John Baldwin
More information about the svn-src-stable-8
mailing list