Skip to contentSkip to conversation

x86: clean up vdso-layout.lds.S

PATCH In review Petr Tesarik 5 participants 15 messages Jun 1, 2009 – Jun 9, 2009 x86

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 x86: clean up vdso-layout.lds.S

The handling of various sections in the VDSO linker script looks pretty haphazard. This patch cleans it up in this regards:

- re-order sections to more closely match the result of a normal shared link
- discard sections which are not useful to user-space
- issue a linker error if a section is encountered which is known not to work
- check that the .got section is empty, except for the three entries defined by the ABI

---
 Makefile          |    5 ++--
 vdso-layout.lds.S |   57 +++++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 51 insertions(+), 11 deletions(-)
arch/x86/vdso/Makefile +3 -2
index 16a9020..8c7f06a 100644
@@ -23,7 +23,8 @@ $(obj)/vdso.o: $(obj)/vdso.so
 
 targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y)
 
-export CPPFLAGS_vdso.lds += -P -C
+vdso-cppflags = -P -C
+export CPPFLAGS_vdso.lds += -m64 $(vdso-cppflags)
 
 VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -Wl,-soname=linux-vdso.so.1 \
 		      	-Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
@@ -68,7 +69,7 @@ vdso32.so-$(VDSO32-y)		+= sysenter
 
 vdso32-images			= $(vdso32.so-y:%=vdso32-%.so)
 
-CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
+CPPFLAGS_vdso32.lds = -m32 $(vdso-cppflags)
 VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -Wl,-soname=linux-gate.so.1
 
 # This makes sure the $(obj) subdirectory exists even though vdso32/
arch/x86/vdso/vdso-layout.lds.S +48 -9

73 lines not on this page · raw message

#1 lore raw

Petr Tesarik píše v Po 01. 06. 2009 v 16:05 +0200:

Quoted 12 lines

The handling of various sections in the VDSO linker script looks pretty haphazard. This patch cleans it up in this regards:

- re-order sections to more closely match the result of a normal shared link
- discard sections which are not useful to user-space
- issue a linker error if a section is encountered which is known not to work
- check that the .got section is empty, except for the three entries defined by the ABI

Quoted 1 line

Any comments on this? It doesn't change anything. It only makes it harder to break vDSOs by accident (such as the latest buglet with TSC synchronization).

Petr Tesarik

Quoted 114 lines
---
 Makefile          |    5 ++--
 vdso-layout.lds.S |   57 +++++++++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 51 insertions(+), 11 deletions(-)
arch/x86/vdso/Makefile +3 -2
index 16a9020..8c7f06a 100644
@@ -23,7 +23,8 @@ $(obj)/vdso.o: $(obj)/vdso.so
 
 targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y)
 
-export CPPFLAGS_vdso.lds += -P -C
+vdso-cppflags = -P -C
+export CPPFLAGS_vdso.lds += -m64 $(vdso-cppflags)
 
 VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -Wl,-soname=linux-vdso.so.1 \
 		      	-Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
@@ -68,7 +69,7 @@ vdso32.so-$(VDSO32-y)		+= sysenter
 
 vdso32-images			= $(vdso32.so-y:%=vdso32-%.so)
 
-CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
+CPPFLAGS_vdso32.lds = -m32 $(vdso-cppflags)
 VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -Wl,-soname=linux-gate.so.1
 
 # This makes sure the $(obj) subdirectory exists even though vdso32/
arch/x86/vdso/vdso-layout.lds.S +48 -10
index 634a2cf..1f4b215 100644
@@ -22,16 +22,15 @@ SECTIONS
 	.eh_frame	: { KEEP (*(.eh_frame)) }	:text
 
 	.dynamic	: { *(.dynamic) }		:text	:dynamic
+	.got		: { *(.got.plt) *(.got) }	:text
 
-	.rodata		: { *(.rodata*) }		:text
+	.rodata		: {
+		*(.rodata .rodata.* .gnu.linkonce.r.*)
+	}
 	.data		: {
-	      *(.data*)
-	      *(.sdata*)
-	      *(.got.plt) *(.got)
-	      *(.gnu.linkonce.d.*)
-	      *(.bss*)
-	      *(.dynbss*)
-	      *(.gnu.linkonce.b.*)
+		*(.data .data.* .gnu.linkonce.d.*)
+		*(.bss .bss.* .gnu.linkonce.b.*)
+		*(COMMON)
 	}
 
 	.altinstructions	: { *(.altinstructions) }
@@ -43,9 +42,49 @@ SECTIONS
 	 */
 	. = ALIGN(0x100);
 
-	.text		: { *(.text*) }			:text	=0x90909090
+	.text		: {
+		*(.text .text.* .gnu.linkonce.t.*)
+	}						:text	=0x90909090
+
+	/* We would need a more sophisticated dynamic linker for the
+	 * vDSO to make the following sections work.  Put them into
+	 * a special section and raise a link-time error if they get
+	 * used.
+	 */
+	.broken		: {
+		/* Code in the Procedure Linkage Table will segfault */
+		*(.plt)
+
+		/* Relocation will not be done, so any pointers will
+		 * still point to the prelinked address, which is wrong
+		 */
+		*(.data.rel.ro*)
+		*(.gnu.linkonce.d.rel.ro.*)
+
+		/* Initialization/termination won't work this way */
+		*(.init) *(.fini)
+		*(.preinit_array) *(.init_array*)
+		*(.fini_array*)
+
+		/* Thread-local data cannot be defined like this */
+		*(.tdata .tdata.* .gnu.linkonce.td.*)
+		*(.tbss .tbss.* .gnu.linkonce.tb.*)
+		*(.tcommon)
+	}
+
+	/* These sections are not useful */
+	/DISCARD/	: {
+		*(.gnu.warning.*)
+		*(.note.GNU-stack)
+	}
 }
 
+ASSERT(!SIZEOF(.broken), "VDSO contains sections that don't work properly");
+
+/* Check that GOT has only the three entries defined by the ABI */
+ASSERT(SIZEOF(.got) == 3*__SIZEOF_POINTER__,
+	"Found extra GOT entries. Check your use of external vars.");
+
 /*
  * Very old versions of ld do not recognize this name token; use the constant.
  */
 
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

Acked-by
#2 lore raw
Quoted 3 lines

Any comments on this? It doesn't change anything. It only makes it harder to break vDSOs by accident (such as the latest buglet with TSC synchronization).

Looks ok to me. Although it would have been nicer if you hadn't mixed that many changes together.

-Andi

#3 lore raw
Quoted 9 lines · Andi Kleen
Quoted 3 lines

Any comments on this? It doesn't change anything. It only makes it harder to break vDSOs by accident (such as the latest buglet with TSC synchronization).

Looks ok to me. Although it would have been nicer if you hadn't mixed that many changes together.

It would have. That makes review harder, and right at the moment time is a bit at a premium. It looks like a good cleanup, but it also looks like it's going to need some testing, which means that since it is not a functional change I would feel best if we could put it on the .32 track after the imminent merge window craziness is over.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#4 lore raw

H. Peter Anvin píše v Pá 05. 06. 2009 v 09:24 -0700:

Quoted 8 lines
Quoted 7 lines · Andi Kleen
Quoted 3 lines

Any comments on this? It doesn't change anything. It only makes it harder to break vDSOs by accident (such as the latest buglet with TSC synchronization).

Looks ok to me. Although it would have been nicer if you hadn't mixed that many changes together.

Quoted 8 lines
Quoted 2 lines

It would have. That makes review harder, and right at the moment time is a bit at a premium. It looks like a good cleanup, but it also looks like it's going to need some testing, which means that since it is not a functional change I would feel best if we could put it on the .32 track after the imminent merge window craziness is over.

You're right. It doesn't make any functional change, so I'm completely fine with taking it on the .32 track.

For the time being, please hold on, as I'm going to split the patch into a series to make reviewing easier. But to be honest, the current content of vdso-layout.lds.S is such mess that I'm convinced it must have been done in a big hurry (and then moved around a few times, so a quick glance at git-blame doesn't tell you that the most messy pieces have been there since the very beginning).

Petr Tesarik

#5 lore raw
In reply to Petr Tesarik
Quoted 11 lines

arch/x86/vdso/Makefile $(obj)/vdso.o: $(obj)/vdso.so · line 27

Quoted 11 lines
arch/x86/vdso/Makefile +2 -1
index 16a9020..8c7f06a 100644
@@ -23,7 +23,8 @@ $(obj)/vdso.o: $(obj)/vdso.so
 
 targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y)
 
-export CPPFLAGS_vdso.lds += -P -C
+vdso-cppflags = -P -C
+export CPPFLAGS_vdso.lds += -m64 $(vdso-cppflags)

I am wondering why we need -P -C here - but we do not need it for lds.S files? Seems like something we could let go.

Quoted 19 lines
Quoted 19 lines
arch/x86/vdso/Makefile +1 -1
 VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -Wl,-soname=linux-vdso.so.1 \
 		      	-Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
@@ -68,7 +69,7 @@ vdso32.so-$(VDSO32-y)		+= sysenter
 
 vdso32-images			= $(vdso32.so-y:%=vdso32-%.so)
 
-CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
+CPPFLAGS_vdso32.lds = -m32 $(vdso-cppflags)
 VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -Wl,-soname=linux-gate.so.1
 
 # This makes sure the $(obj) subdirectory exists even though vdso32/
arch/x86/vdso/vdso-layout.lds.S +0 -0
index 634a2cf..1f4b215 100644
@@ -22,16 +22,15 @@ SECTIONS
 	.eh_frame	: { KEEP (*(.eh_frame)) }	:text
 
Quoted 2 lines

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 25

Quoted 2 lines
arch/x86/vdso/vdso-layout.lds.S +1 -0
 	.dynamic	: { *(.dynamic) }		:text	:dynamic
+	.got		: { *(.got.plt) *(.got) }	:text

The style we try to introduce for .lds files in arch/$ARCH/kernel/vmlinux.lds.S is much more C-like. The above would have been:

	.got : {
		*(.got.plt)
		*(.got)
	} :text

Please use this all over so we have a consistent style in linker scripts.

Quoted 4 lines
Quoted 4 lines
arch/x86/vdso/vdso-layout.lds.S +0 -3
 	.data		: {
-	      *(.data*)
-	      *(.sdata*)
-	      *(.got.plt) *(.got)
Quoted 8 lines

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 34

Quoted 8 lines
arch/x86/vdso/vdso-layout.lds.S +3 -4
-	      *(.gnu.linkonce.d.*)
-	      *(.bss*)
-	      *(.dynbss*)
-	      *(.gnu.linkonce.b.*)
+		*(.data .data.* .gnu.linkonce.d.*)
+		*(.bss .bss.* .gnu.linkonce.b.*)
+		*(COMMON)
 	}

Where did *(.sdata*) go?
Why do we need *(.data .data.*) rather than *(.data*)? *(.dynbss*)?

In your changelog you say:
"discard sections which are not useful to user-space" - but as you do not list which one it is hard to tell what you removed on purpose and what you removed by accident.

Quoted 5 lines

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 43

Quoted 5 lines
arch/x86/vdso/vdso-layout.lds.S +0 -0
 	.altinstructions	: { *(.altinstructions) }
@@ -43,9 +42,49 @@ SECTIONS
 	 */
 	. = ALIGN(0x100);

What is 0x100?

Quoted 39 lines
Quoted 39 lines
arch/x86/vdso/vdso-layout.lds.S +35 -1
-	.text		: { *(.text*) }			:text	=0x90909090
+	.text		: {
+		*(.text .text.* .gnu.linkonce.t.*)
+	}						:text	=0x90909090
+
+	/* We would need a more sophisticated dynamic linker for the
+	 * vDSO to make the following sections work.  Put them into
+	 * a special section and raise a link-time error if they get
+	 * used.
+	 */
+	.broken		: {
+		/* Code in the Procedure Linkage Table will segfault */
+		*(.plt)
+
+		/* Relocation will not be done, so any pointers will
+		 * still point to the prelinked address, which is wrong
+		 */
+		*(.data.rel.ro*)
+		*(.gnu.linkonce.d.rel.ro.*)
+
+		/* Initialization/termination won't work this way */
+		*(.init) *(.fini)
+		*(.preinit_array) *(.init_array*)
+		*(.fini_array*)
+
+		/* Thread-local data cannot be defined like this */
+		*(.tdata .tdata.* .gnu.linkonce.td.*)
+		*(.tbss .tbss.* .gnu.linkonce.tb.*)
+		*(.tcommon)
+	}
+
+	/* These sections are not useful */
+	/DISCARD/	: {
+		*(.gnu.warning.*)
+		*(.note.GNU-stack)
+	}
 }
 
Quoted 1 line

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 82

Quoted 1 line
arch/x86/vdso/vdso-layout.lds.S +1 -0
+ASSERT(!SIZEOF(.broken), "VDSO contains sections that don't work properly");

Can you give any better hints where to look and what to look for?

Quoted 4 lines

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 86

Quoted 4 lines
arch/x86/vdso/vdso-layout.lds.S +4 -0
+
+/* Check that GOT has only the three entries defined by the ABI */
+ASSERT(SIZEOF(.got) == 3*__SIZEOF_POINTER__,
+	"Found extra GOT entries. Check your use of external vars.");

Can you give any better hints where to look and what to look for?

Sam

#6 lore raw

Sam Ravnborg píše v Pá 05. 06. 2009 v 22:07 +0200:

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
arch/x86/vdso/Makefile +0 -0
index 16a9020..8c7f06a 100644
@@ -23,7 +23,8 @@ $(obj)/vdso.o: $(obj)/vdso.so
 
Quoted 8 lines
Quoted 5 lines

arch/x86/vdso/Makefile $(obj)/vdso.o: $(obj)/vdso.so · line 27

Quoted 5 lines
arch/x86/vdso/Makefile +2 -1
 targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y)
 
-export CPPFLAGS_vdso.lds += -P -C
+vdso-cppflags = -P -C
+export CPPFLAGS_vdso.lds += -m64 $(vdso-cppflags)

I am wondering why we need -P -C here - but we do not need it for lds.S files? Seems like something we could let go.

Frankly, I don't know, but it's been there for ages, and I don't see what you mean, anyway. Doesn't the top-level Makefile contain this line, for example:

export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)

Quoted 24 lines
Quoted 18 lines
Quoted 18 lines
arch/x86/vdso/Makefile +1 -1
 VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -Wl,-soname=linux-vdso.so.1 \
 		      	-Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
@@ -68,7 +69,7 @@ vdso32.so-$(VDSO32-y)		+= sysenter
 
 vdso32-images			= $(vdso32.so-y:%=vdso32-%.so)
 
-CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
+CPPFLAGS_vdso32.lds = -m32 $(vdso-cppflags)
 VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -Wl,-soname=linux-gate.so.1
 
 # This makes sure the $(obj) subdirectory exists even though vdso32/
arch/x86/vdso/vdso-layout.lds.S +0 -0
index 634a2cf..1f4b215 100644
@@ -22,16 +22,15 @@ SECTIONS
 	.eh_frame	: { KEEP (*(.eh_frame)) }	:text
 
Quoted 2 lines

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 25

Quoted 2 lines
arch/x86/vdso/vdso-layout.lds.S +1 -0
 	.dynamic	: { *(.dynamic) }		:text	:dynamic
+	.got		: { *(.got.plt) *(.got) }	:text

The style we try to introduce for .lds files in arch/$ARCH/kernel/vmlinux.lds.S is much more C-like. The above would have been:

Quoted 6 lines
	.got : {
		*(.got.plt)
		*(.got)
	} :text

Please use this all over so we have a consistent style in linker scripts.

OK, so should I first post a patch which doesn't change anything but adjusts the coding style of vdso-layout.lds.S?

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
arch/x86/vdso/vdso-layout.lds.S +0 -4
 	.data		: {
-	      *(.data*)
-	      *(.sdata*)
-	      *(.got.plt) *(.got)
-	      *(.gnu.linkonce.d.*)
Quoted 8 lines
Quoted 7 lines

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 34

Quoted 7 lines
arch/x86/vdso/vdso-layout.lds.S +3 -3
-	      *(.bss*)
-	      *(.dynbss*)
-	      *(.gnu.linkonce.b.*)
+		*(.data .data.* .gnu.linkonce.d.*)
+		*(.bss .bss.* .gnu.linkonce.b.*)
+		*(COMMON)
 	}

Where did *(.sdata*) go?

Nothing changed, really. This section is never produced for i386 or x86_64. The line might have been a remnant of the (long abandoned) idea that x86_64 would have .sdata and .data, but it then turned to be rather .data and .ldata.

Quoted 2 lines

Why do we need *(.data .data.*) rather than *(.data*)? *(.dynbss*)?

I don't have any strong opinion here, but the former is exactly what the default linker script has.

Quoted 4 lines

In your changelog you say:
"discard sections which are not useful to user-space" - but as you do not list which one it is hard to tell what you removed on purpose and what you removed by accident.

All those which end up in the section ".broken". I'll make a better wording next time.

Quoted 7 lines
Quoted 5 lines

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 43

Quoted 5 lines
arch/x86/vdso/vdso-layout.lds.S +0 -0
 	.altinstructions	: { *(.altinstructions) }
@@ -43,9 +42,49 @@ SECTIONS
 	 */
 	. = ALIGN(0x100);

What is 0x100?

Um. No idea. Roland, you added this line in commit f6b46ebf904f69a73907a5e6b1ed2228e3f03d9e. Can you shed some light on this magic constant?

Quoted 38 lines
Quoted 38 lines
Quoted 38 lines
arch/x86/vdso/vdso-layout.lds.S +35 -1
-	.text		: { *(.text*) }			:text	=0x90909090
+	.text		: {
+		*(.text .text.* .gnu.linkonce.t.*)
+	}						:text	=0x90909090
+
+	/* We would need a more sophisticated dynamic linker for the
+	 * vDSO to make the following sections work.  Put them into
+	 * a special section and raise a link-time error if they get
+	 * used.
+	 */
+	.broken		: {
+		/* Code in the Procedure Linkage Table will segfault */
+		*(.plt)
+
+		/* Relocation will not be done, so any pointers will
+		 * still point to the prelinked address, which is wrong
+		 */
+		*(.data.rel.ro*)
+		*(.gnu.linkonce.d.rel.ro.*)
+
+		/* Initialization/termination won't work this way */
+		*(.init) *(.fini)
+		*(.preinit_array) *(.init_array*)
+		*(.fini_array*)
+
+		/* Thread-local data cannot be defined like this */
+		*(.tdata .tdata.* .gnu.linkonce.td.*)
+		*(.tbss .tbss.* .gnu.linkonce.tb.*)
+		*(.tcommon)
+	}
+
+	/* These sections are not useful */
+	/DISCARD/	: {
+		*(.gnu.warning.*)
+		*(.note.GNU-stack)
+	}
 }
 
Quoted 2 lines
Quoted 1 line

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 82

Quoted 1 line
arch/x86/vdso/vdso-layout.lds.S +1 -0
+ASSERT(!SIZEOF(.broken), "VDSO contains sections that don't work properly");

Can you give any better hints where to look and what to look for?

What would you expect? The linker script language is quite limited in its capabilities... Best I could do is split the ".broken" section into several sections and move the descriptions from the individual comments above here. If this muckle of empty ".broken.*" sections gets correctly discarded and triggers no bug in binutils, I can probably do it.

Quoted 5 lines
Quoted 4 lines

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 86

Quoted 4 lines
arch/x86/vdso/vdso-layout.lds.S +4 -0
+
+/* Check that GOT has only the three entries defined by the ABI */
+ASSERT(SIZEOF(.got) == 3*__SIZEOF_POINTER__,
+	"Found extra GOT entries. Check your use of external vars.");

Can you give any better hints where to look and what to look for?

What would you consider a better hint? If there are any entries in the GOT, this means that the vDSO tries to access an external function or variable. But since we don't have a real in-kernel linker for the vDSO, these references will remain unresolved (and most likely cause a segmentation fault at run-time).

Cheers,
Petr Tesarik

#7 lore raw
Quoted 2 lines
Quoted 2 lines

I am wondering why we need -P -C here - but we do not need it for lds.S files? Seems like something we could let go.

AFAIK these only affect readability of the lds.s output files. The difference should be entirely cosmetic.

Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 43

Quoted 4 lines
arch/x86/vdso/vdso-layout.lds.S +0 -0
 	.altinstructions	: { *(.altinstructions) }
@@ -43,9 +42,49 @@ SECTIONS
 	 */
 	. = ALIGN(0x100);

What is 0x100?

Um. No idea. Roland, you added this line in commit f6b46ebf904f69a73907a5e6b1ed2228e3f03d9e. Can you shed some light on this magic constant?

You mean this one:

	/*
	 * Align the actual code well away from the non-instruction data.
	 * This is the best thing for the I-cache.
	 */
	. = ALIGN(0x100);

Reading the comment might make it obvious that it's intended for optimal code alignment. I suspect someone at the time told me 256 is as big as an I-cache line was ever likely to get. You could use L1_CACHE_BYTES instead I suppose.

Quoted 5 lines

What would you expect? The linker script language is quite limited in its capabilities... Best I could do is split the ".broken" section into several sections and move the descriptions from the individual comments above here. If this muckle of empty ".broken.*" sections gets correctly discarded and triggers no bug in binutils, I can probably do it.

Adding more sections and section names unnecessarily bloats the size of the vDSO image. Keep the set of output sections to the necessary minimum.

Thanks,
Roland

#8 lore raw

Roland McGrath píše v Út 09. 06. 2009 v 00:52 -0700:

Quoted 30 lines
Quoted 2 lines
Quoted 2 lines

I am wondering why we need -P -C here - but we do not need it for lds.S files? Seems like something we could let go.

AFAIK these only affect readability of the lds.s output files. The difference should be entirely cosmetic.

Quoted 10 lines
Quoted 6 lines
Quoted 4 lines

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 43

Quoted 4 lines
arch/x86/vdso/vdso-layout.lds.S +0 -0
 	.altinstructions	: { *(.altinstructions) }
@@ -43,9 +42,49 @@ SECTIONS
 	 */
 	. = ALIGN(0x100);

What is 0x100?

Um. No idea. Roland, you added this line in commit f6b46ebf904f69a73907a5e6b1ed2228e3f03d9e. Can you shed some light on this magic constant?

You mean this one:

	/*
	 * Align the actual code well away from the non-instruction data.
	 * This is the best thing for the I-cache.
	 */
	. = ALIGN(0x100);

Reading the comment might make it obvious that it's intended for optimal code alignment. I suspect someone at the time told me 256 is as big as an I-cache line was ever likely to get. You could use L1_CACHE_BYTES instead I suppose.

Quoted 8 lines
Quoted 5 lines

What would you expect? The linker script language is quite limited in its capabilities... Best I could do is split the ".broken" section into several sections and move the descriptions from the individual comments above here. If this muckle of empty ".broken.*" sections gets correctly discarded and triggers no bug in binutils, I can probably do it.

Adding more sections and section names unnecessarily bloats the size of the vDSO image. Keep the set of output sections to the necessary minimum.

Which version of binutils are you using? I'm using binutils-2.19, and all empty sections get completely discarded, i.e. they do not affect the size of the output in any way.

Petr Tesarik

#9 lore raw
Quoted 3 lines

Which version of binutils are you using? I'm using binutils-2.19, and all empty sections get completely discarded, i.e. they do not affect the size of the output in any way.

Oh, empty, sure. So then what is ".broken" for at all?
I thought this was for the nonempty-but-useless ones like .got et al that the linker will insist on creating but we don't really need in the vDSO.

Thanks,
Roland

#10 lore raw

Roland McGrath píše v Út 09. 06. 2009 v 01:09 -0700:

Quoted 7 lines
Quoted 3 lines

Which version of binutils are you using? I'm using binutils-2.19, and all empty sections get completely discarded, i.e. they do not affect the size of the output in any way.

Oh, empty, sure. So then what is ".broken" for at all?
I thought this was for the nonempty-but-useless ones like .got et al that the linker will insist on creating but we don't really need in the vDSO.

No, that's for collecting sections which should never ever appear in a vDSO. Or rather, when these sections do appear in a vDSO, I know for sure that the resulting vDSO will not work properly.

Petr Tesarik

#11 lore raw
In reply to Roland McGrath
Quoted 9 lines · Roland McGrath

You mean this one:

	/*
	 * Align the actual code well away from the non-instruction data.
	 * This is the best thing for the I-cache.
	 */
	. = ALIGN(0x100);
Quoted 5 lines

Reading the comment might make it obvious that it's intended for optimal code alignment. I suspect someone at the time told me 256 is as big as an I-cache line was ever likely to get. You could use L1_CACHE_BYTES instead I suppose.

Most likely 256 was chosen as a compromise between the the then-documented value for coherency avoidance (128), future-proofing, and waste.

I don't think we want to use different values on different platforms, and end up with dramatically different vdsos when they still need to fit in the same size envelope.

-hpa

Signature · 2 lines
H. Peter Anvin, Intel Open Source Technology Center
I work for Intel.  I don't speak on their behalf.
#12 lore raw
In reply to Petr Tesarik
Quoted 16 lines · Petr Tesarik

Sam Ravnborg píše v Pá 05. 06. 2009 v 22:07 +0200:

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
arch/x86/vdso/Makefile +0 -0
index 16a9020..8c7f06a 100644
@@ -23,7 +23,8 @@ $(obj)/vdso.o: $(obj)/vdso.so
 
Quoted 8 lines
Quoted 5 lines

arch/x86/vdso/Makefile $(obj)/vdso.o: $(obj)/vdso.so · line 27

Quoted 5 lines
arch/x86/vdso/Makefile +2 -1
 targets += vdso.so vdso.so.dbg vdso.lds $(vobjs-y)
 
-export CPPFLAGS_vdso.lds += -P -C
+vdso-cppflags = -P -C
+export CPPFLAGS_vdso.lds += -m64 $(vdso-cppflags)

I am wondering why we need -P -C here - but we do not need it for lds.S files? Seems like something we could let go.

Quoted 5 lines

Frankly, I don't know, but it's been there for ages, and I don't see what you mean, anyway. Doesn't the top-level Makefile contain this line, for example:

export CPPFLAGS_vmlinux.lds += -P -C -U$(ARCH)

I had forgotten about the top-level Makefile setting these. They should have moved to Makefile.build long time ago :-(

Keep them here.

Quoted 30 lines
Quoted 30 lines
Quoted 19 lines
Quoted 19 lines
arch/x86/vdso/Makefile +1 -1
 VDSO_LDFLAGS_vdso.lds = -m elf_x86_64 -Wl,-soname=linux-vdso.so.1 \
 		      	-Wl,-z,max-page-size=4096 -Wl,-z,common-page-size=4096
@@ -68,7 +69,7 @@ vdso32.so-$(VDSO32-y)		+= sysenter
 
 vdso32-images			= $(vdso32.so-y:%=vdso32-%.so)
 
-CPPFLAGS_vdso32.lds = $(CPPFLAGS_vdso.lds)
+CPPFLAGS_vdso32.lds = -m32 $(vdso-cppflags)
 VDSO_LDFLAGS_vdso32.lds = -m elf_i386 -Wl,-soname=linux-gate.so.1
 
 # This makes sure the $(obj) subdirectory exists even though vdso32/
arch/x86/vdso/vdso-layout.lds.S +0 -0
index 634a2cf..1f4b215 100644
@@ -22,16 +22,15 @@ SECTIONS
 	.eh_frame	: { KEEP (*(.eh_frame)) }	:text
 
Quoted 2 lines

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 25

Quoted 2 lines
arch/x86/vdso/vdso-layout.lds.S +1 -0
 	.dynamic	: { *(.dynamic) }		:text	:dynamic
+	.got		: { *(.got.plt) *(.got) }	:text

The style we try to introduce for .lds files in arch/$ARCH/kernel/vmlinux.lds.S is much more C-like. The above would have been:

	.got : {
		*(.got.plt)
		*(.got)
	} :text
Quoted 4 lines
Quoted 1 line

Please use this all over so we have a consistent style in linker scripts.

OK, so should I first post a patch which doesn't change anything but adjusts the coding style of vdso-layout.lds.S?

That would be great.
Then your following changes would be easier to read/review.

Quoted 21 lines
Quoted 15 lines
Quoted 14 lines
Quoted 4 lines
arch/x86/vdso/vdso-layout.lds.S +0 -1
 	.data		: {
-	      *(.data*)

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 34

Quoted 10 lines
arch/x86/vdso/vdso-layout.lds.S +3 -6
-	      *(.sdata*)
-	      *(.got.plt) *(.got)
-	      *(.gnu.linkonce.d.*)
-	      *(.bss*)
-	      *(.dynbss*)
-	      *(.gnu.linkonce.b.*)
+		*(.data .data.* .gnu.linkonce.d.*)
+		*(.bss .bss.* .gnu.linkonce.b.*)
+		*(COMMON)
 	}

Where did *(.sdata*) go?

Nothing changed, really. This section is never produced for i386 or x86_64. The line might have been a remnant of the (long abandoned) idea that x86_64 would have .sdata and .data, but it then turned to be rather .data and .ldata.

Quoted 5 lines
Quoted 2 lines

Why do we need *(.data .data.*) rather than *(.data*)? *(.dynbss*)?

I don't have any strong opinion here, but the former is exactly what the default linker script has.

My general take on this is that we should know and deal with what the linker produces. So if we only expect .data then .data.* could go into .broken so we catch it.

Quoted 11 lines
Quoted 5 lines

In your changelog you say:
"discard sections which are not useful to user-space" - but as you do not list which one it is hard to tell what you removed on purpose and what you removed by accident.

All those which end up in the section ".broken". I'll make a better wording next time.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
arch/x86/vdso/vdso-layout.lds.S +0 -0
 }
 
Quoted 8 lines
Quoted 2 lines
Quoted 1 line

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 82

Quoted 1 line
arch/x86/vdso/vdso-layout.lds.S +1 -0
+ASSERT(!SIZEOF(.broken), "VDSO contains sections that don't work properly");

Can you give any better hints where to look and what to look for?

What would you expect? The linker script language is quite limited in its capabilities... Best I could do is split the ".broken" section into several sections and move the descriptions from the individual comments above here. If this muckle of empty ".broken.*" sections gets correctly discarded and triggers no bug in binutils, I can probably do it.

I was more think of something like this:

+/*
+ * This assert is triggered if the linker produces a non-empty section
+ * that is listed in the .broken section.
+ * Use objdump -h to see which is the offending section
+ */
+ASSERT(!SIZEOF(.broken), "The vdso linker script found a section that is bad. See xx.lds for details");

Quoted 10 lines
Quoted 4 lines
Quoted 3 lines

arch/x86/vdso/vdso-layout.lds.S SECTIONS · line 86

Quoted 3 lines
arch/x86/vdso/vdso-layout.lds.S +3 -0
+/* Check that GOT has only the three entries defined by the ABI */
+ASSERT(SIZEOF(.got) == 3*__SIZEOF_POINTER__,
+	"Found extra GOT entries. Check your use of external vars.");

Can you give any better hints where to look and what to look for?

What would you consider a better hint? If there are any entries in the GOT, this means that the vDSO tries to access an external function or variable. But since we don't have a real in-kernel linker for the vDSO, these references will remain unresolved (and most likely cause a segmentation fault at run-time).

And here reword the above explanation a bit and give a hint how to see what is there that is unexpected.
And stuff it in a comment.

Sam

#13 lore raw
Quoted 9 lines · Sam Ravnborg
Quoted 5 lines
Quoted 3 lines

Why do we need *(.data .data.*) rather than *(.data*)? *(.dynbss*)?

I don't have any strong opinion here, but the former is exactly what the default linker script has.

My general take on this is that we should know and deal with what the linker produces. So if we only expect .data then .data.* could go into .broken so we catch it.

That will break if we change to per-function sections.

-hpa

#14 lore raw
Quoted 4 lines · H. Peter Anvin
Quoted 3 lines · Sam Ravnborg
Quoted 3 lines
Quoted 3 lines

Why do we need *(.data .data.*) rather than *(.data*)? *(.dynbss*)?

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

I don't have any strong opinion here, but the former is exactly what the default linker script has.

My general take on this is that we should know and deal with what the linker produces. So if we only expect .data then .data.* could go into .broken so we catch it.

That will break if we change to per-function sections.

But adding it to .broken would catch this at first build which would have told us so.
We shall try to make it -ffunction-sections compatible in first try though.

Sam