Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[PATCH] vDSO hash-style fix

The latest toolchains can produce a new ELF section in DSOs and
dynamically-linked executables. The new section ".gnu.hash" replaces
".hash", and allows for more efficient runtime symbol lookups by the
dynamic linker. The new ld option --hash-style={sysv|gnu|both} controls
whether to produce the old ".hash", the new ".gnu.hash", or both. In some
new systems such as Fedora Core 6, gcc by default passes --hash-style=gnu
to the linker, so that a standard invocation of "gcc -shared" results in
producing a DSO with only ".gnu.hash". The new ".gnu.hash" sections need
to be dealt with the same way as ".hash" sections in all respects; only the
dynamic linker cares about their contents. To work with older dynamic
linkers (i.e. preexisting releases of glibc), a binary must have the old
".hash" section. The --hash-style=both option produces binaries that a new
dynamic linker can use more efficiently, but an old dynamic linker can
still handle.

The new section runs afoul of the custom linker scripts used to build vDSO
images for the kernel. On ia64, the failure mode for this is a boot-time
panic because the vDSO's PT_IA_64_UNWIND segment winds up ill-formed.

This patch addresses the problem in two ways.

First, it mentions ".gnu.hash" in all the linker scripts alongside ".hash".
This produces correct vDSO images with --hash-style=sysv (or old tools),
with --hash-style=gnu, or with --hash-style=both.

Second, it passes the --hash-style=sysv option when building the vDSO
images, so that ".gnu.hash" is not actually produced. This is the most
conservative choice for compatibility with any old userland. There is some
concern that some ancient glibc builds (though not any known old production
system) might choke on --hash-style=both binaries. The optimizations
provided by the new style of hash section do not really matter for a DSO
with a tiny number of symbols, as the vDSO has. If someone wants to use
=gnu or =both for their vDSO builds and worry less about that
compatibility, just change the option and the linker script changes will
make any choice work fine.

Signed-off-by: Roland McGrath <roland@redhat.com>
Cc: "Luck, Tony" <tony.luck@intel.com>
Cc: Kyle McMartin <kyle@mcmartin.ca>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Jeff Dike <jdike@addtoit.com>
Cc: Andi Kleen <ak@muc.de>
Cc: Sam Ravnborg <sam@ravnborg.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>

authored by

Roland McGrath and committed by
Linus Torvalds
0b0bf7a3 072d3d1a

+38 -4
+14
Documentation/kbuild/makefiles.txt
··· 407 407 The second argument is optional, and if supplied will be used 408 408 if first argument is not supported. 409 409 410 + ld-option 411 + ld-option is used to check if $(CC) when used to link object files 412 + supports the given option. An optional second option may be 413 + specified if first option are not supported. 414 + 415 + Example: 416 + #arch/i386/kernel/Makefile 417 + vsyscall-flags += $(call ld-option, -Wl$(comma)--hash-style=sysv) 418 + 419 + In the above example vsyscall-flags will be assigned the option 420 + -Wl$(comma)--hash-style=sysv if it is supported by $(CC). 421 + The second argument is optional, and if supplied will be used 422 + if first argument is not supported. 423 + 410 424 cc-option 411 425 cc-option is used to check if $(CC) support a given option, and not 412 426 supported to use an optional second option.
+2 -1
arch/i386/kernel/Makefile
··· 59 59 60 60 export CPPFLAGS_vsyscall.lds += -P -C -U$(ARCH) 61 61 62 - vsyscall-flags = -shared -s -Wl,-soname=linux-gate.so.1 62 + vsyscall-flags = -shared -s -Wl,-soname=linux-gate.so.1 \ 63 + $(call ld-option, -Wl$(comma)--hash-style=sysv) 63 64 SYSCFLAGS_vsyscall-sysenter.so = $(vsyscall-flags) 64 65 SYSCFLAGS_vsyscall-int80.so = $(vsyscall-flags) 65 66
+1
arch/i386/kernel/vsyscall.lds.S
··· 10 10 . = VDSO_PRELINK + SIZEOF_HEADERS; 11 11 12 12 .hash : { *(.hash) } :text 13 + .gnu.hash : { *(.gnu.hash) } 13 14 .dynsym : { *(.dynsym) } 14 15 .dynstr : { *(.dynstr) } 15 16 .gnu.version : { *(.gnu.version) }
+2 -1
arch/ia64/kernel/Makefile
··· 45 45 quiet_cmd_gate = GATE $@ 46 46 cmd_gate = $(CC) -nostdlib $(GATECFLAGS_$(@F)) -Wl,-T,$(filter-out FORCE,$^) -o $@ 47 47 48 - GATECFLAGS_gate.so = -shared -s -Wl,-soname=linux-gate.so.1 48 + GATECFLAGS_gate.so = -shared -s -Wl,-soname=linux-gate.so.1 \ 49 + $(call ld-option, -Wl$(comma)--hash-style=sysv) 49 50 $(obj)/gate.so: $(obj)/gate.lds $(obj)/gate.o FORCE 50 51 $(call if_changed,gate) 51 52
+1
arch/ia64/kernel/gate.lds.S
··· 12 12 . = GATE_ADDR + SIZEOF_HEADERS; 13 13 14 14 .hash : { *(.hash) } :readable 15 + .gnu.hash : { *(.gnu.hash) } 15 16 .dynsym : { *(.dynsym) } 16 17 .dynstr : { *(.dynstr) } 17 18 .gnu.version : { *(.gnu.version) }
+1
arch/parisc/kernel/vmlinux.lds.S
··· 204 204 *(.dynstr) 205 205 *(.dynamic) 206 206 *(.hash) 207 + *(.gnu.hash) 207 208 #endif 208 209 } 209 210
+2 -1
arch/powerpc/kernel/vdso32/Makefile
··· 14 14 15 15 16 16 EXTRA_CFLAGS := -shared -s -fno-common -fno-builtin 17 - EXTRA_CFLAGS += -nostdlib -Wl,-soname=linux-vdso32.so.1 17 + EXTRA_CFLAGS += -nostdlib -Wl,-soname=linux-vdso32.so.1 \ 18 + $(call ld-option, -Wl$(comma)--hash-style=sysv) 18 19 EXTRA_AFLAGS := -D__VDSO32__ -s 19 20 20 21 obj-y += vdso32_wrapper.o
+1
arch/powerpc/kernel/vdso32/vdso32.lds.S
··· 14 14 { 15 15 . = VDSO32_LBASE + SIZEOF_HEADERS; 16 16 .hash : { *(.hash) } :text 17 + .gnu.hash : { *(.gnu.hash) } 17 18 .dynsym : { *(.dynsym) } 18 19 .dynstr : { *(.dynstr) } 19 20 .gnu.version : { *(.gnu.version) }
+2 -1
arch/powerpc/kernel/vdso64/Makefile
··· 8 8 obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) 9 9 10 10 EXTRA_CFLAGS := -shared -s -fno-common -fno-builtin 11 - EXTRA_CFLAGS += -nostdlib -Wl,-soname=linux-vdso64.so.1 11 + EXTRA_CFLAGS += -nostdlib -Wl,-soname=linux-vdso64.so.1 \ 12 + $(call ld-option, -Wl$(comma)--hash-style=sysv) 12 13 EXTRA_AFLAGS := -D__VDSO64__ -s 13 14 14 15 obj-y += vdso64_wrapper.o
+1
arch/powerpc/kernel/vdso64/vdso64.lds.S
··· 12 12 { 13 13 . = VDSO64_LBASE + SIZEOF_HEADERS; 14 14 .hash : { *(.hash) } :text 15 + .gnu.hash : { *(.gnu.hash) } 15 16 .dynsym : { *(.dynsym) } 16 17 .dynstr : { *(.dynstr) } 17 18 .gnu.version : { *(.gnu.version) }
+1
arch/ppc/kernel/vmlinux.lds.S
··· 8 8 . = + SIZEOF_HEADERS; 9 9 .interp : { *(.interp) } 10 10 .hash : { *(.hash) } 11 + .gnu.hash : { *(.gnu.hash) } 11 12 .dynsym : { *(.dynsym) } 12 13 .dynstr : { *(.dynstr) } 13 14 .rel.text : { *(.rel.text) }
+1
arch/um/kernel/dyn.lds.S
··· 26 26 27 27 /* Read-only sections, merged into text segment: */ 28 28 .hash : { *(.hash) } 29 + .gnu.hash : { *(.gnu.hash) } 29 30 .dynsym : { *(.dynsym) } 30 31 .dynstr : { *(.dynstr) } 31 32 .gnu.version : { *(.gnu.version) }
+1
arch/x86_64/ia32/Makefile
··· 23 23 # The DSO images are built using a special linker script 24 24 quiet_cmd_syscall = SYSCALL $@ 25 25 cmd_syscall = $(CC) -m32 -nostdlib -shared -s \ 26 + $(call ld-option, -Wl$(comma)--hash-style=sysv) \ 26 27 -Wl,-soname=linux-gate.so.1 -o $@ \ 27 28 -Wl,-T,$(filter-out FORCE,$^) 28 29
+1
arch/x86_64/ia32/vsyscall.lds
··· 11 11 . = VSYSCALL_BASE + SIZEOF_HEADERS; 12 12 13 13 .hash : { *(.hash) } :text 14 + .gnu.hash : { *(.gnu.hash) } 14 15 .dynsym : { *(.dynsym) } 15 16 .dynstr : { *(.dynstr) } 16 17 .gnu.version : { *(.gnu.version) }
+7
scripts/Kbuild.include
··· 85 85 cc-ifversion = $(shell if [ $(call cc-version, $(CC)) $(1) $(2) ]; then \ 86 86 echo $(3); fi;) 87 87 88 + # ld-option 89 + # Usage: ldflags += $(call ld-option, -Wl$(comma)--hash-style=both) 90 + ld-option = $(shell if $(CC) $(1) \ 91 + -nostdlib -o ldtest$$$$.out -xc /dev/null \ 92 + > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi; \ 93 + rm -f ldtest$$$$.out) 94 + 88 95 ### 89 96 # Shorthand for $(Q)$(MAKE) -f scripts/Makefile.build obj= 90 97 # Usage: