zero size set_pcpu linker sets

Navdeep Parhar nparhar at gmail.com
Tue Nov 24 18:53:11 UTC 2009


objdump -h shows that most, but not all, KLDs on amd64 have a "set_pcpu"
section of size 0.  Why?  What is the difference between having a 0
sized set_pcpu vs. not having it at all?

The kernel linker considers the alignment requirements of these empty
sections and advances mapsize/mapbase.  This bothers my kgdb (which is
slightly modified to deal with amd64 KLDs).

I'm using the patch shown here as a stopgap measure.  I think the correct
fix is to not have these empty sections in the KLD to begin with.

Regards,
Navdeep

diff -r 09b877bb00f2 sys/kern/link_elf_obj.c
--- a/sys/kern/link_elf_obj.c   Mon Nov 23 12:42:09 2009 -0800
+++ b/sys/kern/link_elf_obj.c   Tue Nov 24 10:13:02 2009 -0800
@@ -680,10 +680,12 @@
                switch (shdr[i].sh_type) {
                case SHT_PROGBITS:
                case SHT_NOBITS:
-                       alignmask = shdr[i].sh_addralign - 1;
-                       mapsize += alignmask;
-                       mapsize &= ~alignmask;
-                       mapsize += shdr[i].sh_size;
+                       if (shdr[i].sh_size) {
+                               alignmask = shdr[i].sh_addralign - 1;
+                               mapsize += alignmask;
+                               mapsize &= ~alignmask;
+                               mapsize += shdr[i].sh_size;
+                       }
                        break;
                }
        }
@@ -740,9 +742,15 @@
                switch (shdr[i].sh_type) {
                case SHT_PROGBITS:
                case SHT_NOBITS:
-                       alignmask = shdr[i].sh_addralign - 1;
-                       mapbase += alignmask;
-                       mapbase &= ~alignmask;
+                       if (shdr[i].sh_size) {
+                               alignmask = shdr[i].sh_addralign - 1;
+                               mapbase += alignmask;
+                               mapbase &= ~alignmask;
+                       }
                        if (ef->shstrtab && shdr[i].sh_name != 0)
                                ef->progtab[pb].name =
                                    ef->shstrtab + shdr[i].sh_name;


More information about the freebsd-hackers mailing list