Skip to contentSkip to conversation

x86_64: Work around old gas bug

PATCH In review Tao Guo 4 participants 8 messages Sep 26, 2012 – Sep 27, 2012 x86

lore
Share & tools
lore

Tao Guo

author
#0 lore raw

PATCH 1/1 x86_64: Work around old gas bug

gas in binutils(2.16.91) could not parse parentheses within macro parameters unless fully parenthesized, and this is a workaround to make old gas work without generating below errors:
arch/x86/kernel/entry_64.S: Assembler messages:
arch/x86/kernel/entry_64.S:387: Error: too many positional arguments arch/x86/kernel/entry_64.S:389: Error: too many positional arguments arch/x86/kernel/entry_64.S:390: Error: too many positional arguments arch/x86/kernel/entry_64.S:391: Error: too many positional arguments arch/x86/kernel/entry_64.S:392: Error: too many positional arguments arch/x86/kernel/entry_64.S:393: Error: too many positional arguments arch/x86/kernel/entry_64.S:394: Error: too many positional arguments

---
 arch/x86/include/asm/calling.h |   48 +++++++++++++++++++--------------------
 arch/x86/kernel/entry_64.S     |   20 ++++++++--------
 2 files changed, 33 insertions(+), 35 deletions(-)
arch/x86/include/asm/calling.h +23 -25
index a9e3a74..7f8422a 100644
@@ -49,38 +49,36 @@ For 32-bit we have the following conventions - kernel is built with
 #include "dwarf2.h"
 
 /*
- * 64-bit system call stack frame layout defines and helpers, for
- * assembly code (note that the seemingly unnecessary parentheses
- * are to prevent cpp from inserting spaces in expressions that get
- * passed to macros):
+ * 64-bit system call stack frame layout defines and helpers,
+ * for assembly code:
  */
 
-#define R15		  (0)
-#define R14		  (8)
-#define R13		 (16)
-#define R12		 (24)
-#define RBP		 (32)
-#define RBX		 (40)
+#define R15		  0
+#define R14		  8
+#define R13		 16
+#define R12		 24
+#define RBP		 32
+#define RBX		 40
 
 /* arguments: interrupts/non tracing syscalls only save up to here: */
-#define R11		 (48)
-#define R10		 (56)
-#define R9		 (64)
-#define R8		 (72)
-#define RAX		 (80)
-#define RCX		 (88)
-#define RDX		 (96)
-#define RSI		(104)
-#define RDI		(112)
-#define ORIG_RAX	(120)       /* + error_code */
+#define R11		 48
+#define R10		 56
+#define R9		 64
+#define R8		 72
+#define RAX		 80
+#define RCX		 88
+#define RDX		 96
+#define RSI		104
+#define RDI		112
+#define ORIG_RAX	120       /* + error_code */
 /* end of arguments */
 
 /* cpu exception frame or undefined in case of fast syscall: */
-#define RIP		(128)
-#define CS		(136)
-#define EFLAGS		(144)
-#define RSP		(152)
-#define SS		(160)
+#define RIP		128
+#define CS		136
+#define EFLAGS		144
+#define RSP		152
+#define SS		160
 
 #define ARGOFFSET	R11
 #define SWFRAME		ORIG_RAX
arch/x86/kernel/entry_64.S +10 -10
index 69babd8..bf77e70 100644
@@ -342,15 +342,15 @@ ENDPROC(native_usergs_sysret64)
 	.macro SAVE_ARGS_IRQ
 	cld
 	/* start from rbp in pt_regs and jump over */
-	movq_cfi rdi, RDI-RBP
-	movq_cfi rsi, RSI-RBP
-	movq_cfi rdx, RDX-RBP
-	movq_cfi rcx, RCX-RBP
-	movq_cfi rax, RAX-RBP
-	movq_cfi  r8,  R8-RBP
-	movq_cfi  r9,  R9-RBP
-	movq_cfi r10, R10-RBP
-	movq_cfi r11, R11-RBP
+	movq_cfi rdi, (RDI-RBP)
+	movq_cfi rsi, (RSI-RBP)
+	movq_cfi rdx, (RDX-RBP)
+	movq_cfi rcx, (RCX-RBP)
+	movq_cfi rax, (RAX-RBP)
+	movq_cfi  r8,  (R8-RBP)
+	movq_cfi  r9,  (R9-RBP)
+	movq_cfi r10, (R10-RBP)
+	movq_cfi r11, (R11-RBP)
 
 	/* Save rbp so that we can unwind from get_irq_regs() */
 	movq_cfi rbp, 0
@@ -384,7 +384,7 @@ ENDPROC(native_usergs_sysret64)
 	.endm
 
 ENTRY(save_rest)
-	PARTIAL_FRAME 1 REST_SKIP+8
+	PARTIAL_FRAME 1 (REST_SKIP+8)
 	movq 5*8+16(%rsp), %r11	/* save return address */
 	movq_cfi rbx, RBX+16
 	movq_cfi rbp, RBP+16
Signature · 1 line
1.7.7.6
#1 lore raw
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Tao Guo

gas in binutils(2.16.91) could not parse parentheses within macro parameters unless fully parenthesized, and this is a workaround to make old gas work without generating below errors:
arch/x86/kernel/entry_64.S: Assembler messages:
arch/x86/kernel/entry_64.S:387: Error: too many positional arguments arch/x86/kernel/entry_64.S:389: Error: too many positional arguments arch/x86/kernel/entry_64.S:390: Error: too many positional arguments arch/x86/kernel/entry_64.S:391: Error: too many positional arguments arch/x86/kernel/entry_64.S:392: Error: too many positional arguments arch/x86/kernel/entry_64.S:393: Error: too many positional arguments arch/x86/kernel/entry_64.S:394: Error: too many positional arguments

Quoted 1 line

This looks okay now to me, but I'm somewhat reluctant to formally ack it given that we know how broken those particular gas versions are.

Jan

Quoted 112 lines
---
 arch/x86/include/asm/calling.h |   48 +++++++++++++++++++--------------------
 arch/x86/kernel/entry_64.S     |   20 ++++++++--------
 2 files changed, 33 insertions(+), 35 deletions(-)
arch/x86/include/asm/calling.h +0 -0
index a9e3a74..7f8422a 100644
@@ -49,38 +49,36 @@ For 32-bit we have the following conventions - kernel is 

built with
#include "dwarf2.h"

/*
- * 64-bit system call stack frame layout defines and helpers, for
- * assembly code (note that the seemingly unnecessary parentheses
- * are to prevent cpp from inserting spaces in expressions that get
- * passed to macros):
+ * 64-bit system call stack frame layout defines and helpers,
+ * for assembly code:
*/

arch/x86/include/asm/calling.h +21 -21
-#define R15		  (0)
-#define R14		  (8)
-#define R13		 (16)
-#define R12		 (24)
-#define RBP		 (32)
-#define RBX		 (40)
+#define R15		  0
+#define R14		  8
+#define R13		 16
+#define R12		 24
+#define RBP		 32
+#define RBX		 40
 
 /* arguments: interrupts/non tracing syscalls only save up to here: */
-#define R11		 (48)
-#define R10		 (56)
-#define R9		 (64)
-#define R8		 (72)
-#define RAX		 (80)
-#define RCX		 (88)
-#define RDX		 (96)
-#define RSI		(104)
-#define RDI		(112)
-#define ORIG_RAX	(120)       /* + error_code */
+#define R11		 48
+#define R10		 56
+#define R9		 64
+#define R8		 72
+#define RAX		 80
+#define RCX		 88
+#define RDX		 96
+#define RSI		104
+#define RDI		112
+#define ORIG_RAX	120       /* + error_code */
 /* end of arguments */
 
 /* cpu exception frame or undefined in case of fast syscall: */
-#define RIP		(128)
-#define CS		(136)
-#define EFLAGS		(144)
-#define RSP		(152)
-#define SS		(160)
+#define RIP		128
+#define CS		136
+#define EFLAGS		144
+#define RSP		152
+#define SS		160
 
 #define ARGOFFSET	R11
 #define SWFRAME		ORIG_RAX
arch/x86/kernel/entry_64.S +10 -10
index 69babd8..bf77e70 100644
@@ -342,15 +342,15 @@ ENDPROC(native_usergs_sysret64)
 	.macro SAVE_ARGS_IRQ
 	cld
 	/* start from rbp in pt_regs and jump over */
-	movq_cfi rdi, RDI-RBP
-	movq_cfi rsi, RSI-RBP
-	movq_cfi rdx, RDX-RBP
-	movq_cfi rcx, RCX-RBP
-	movq_cfi rax, RAX-RBP
-	movq_cfi  r8,  R8-RBP
-	movq_cfi  r9,  R9-RBP
-	movq_cfi r10, R10-RBP
-	movq_cfi r11, R11-RBP
+	movq_cfi rdi, (RDI-RBP)
+	movq_cfi rsi, (RSI-RBP)
+	movq_cfi rdx, (RDX-RBP)
+	movq_cfi rcx, (RCX-RBP)
+	movq_cfi rax, (RAX-RBP)
+	movq_cfi  r8,  (R8-RBP)
+	movq_cfi  r9,  (R9-RBP)
+	movq_cfi r10, (R10-RBP)
+	movq_cfi r11, (R11-RBP)
 
 	/* Save rbp so that we can unwind from get_irq_regs() */
 	movq_cfi rbp, 0
@@ -384,7 +384,7 @@ ENDPROC(native_usergs_sysret64)
 	.endm
 
 ENTRY(save_rest)
-	PARTIAL_FRAME 1 REST_SKIP+8
+	PARTIAL_FRAME 1 (REST_SKIP+8)
 	movq 5*8+16(%rsp), %r11	/* save return address */
 	movq_cfi rbx, RBX+16
 	movq_cfi rbp, RBP+16
Signature · 1 line
1.7.7.6
#2 lore raw
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Tao Guo

gas in binutils(2.16.91) could not parse parentheses within macro parameters unless fully parenthesized, and this is a workaround to make old gas work without generating below errors:
arch/x86/kernel/entry_64.S: Assembler messages:
arch/x86/kernel/entry_64.S:387: Error: too many positional arguments arch/x86/kernel/entry_64.S:389: Error: too many positional arguments arch/x86/kernel/entry_64.S:390: Error: too many positional arguments arch/x86/kernel/entry_64.S:391: Error: too many positional arguments arch/x86/kernel/entry_64.S:392: Error: too many positional arguments arch/x86/kernel/entry_64.S:393: Error: too many positional arguments arch/x86/kernel/entry_64.S:394: Error: too many positional arguments

Quoted 5 lines
Quoted 1 line

This looks okay now to me, but I'm somewhat reluctant to formally ack it given that we know how broken those particular gas versions are.

Well, assuming Tao Guo test-booted a kernel build with this old GAS version, we could apply this patch on a best-effort basis - the changes don't look particularly ugly. If other, unacceptable uglies or fragilities come up then we might balk.

Agreed?

Thanks,

Ingo

#3 lore raw
Quoted 23 lines
Quoted 1 line
Quoted 1 line · Ingo Molnar
Quoted 13 lines · Jan Beulich
Quoted 13 lines
Quoted 1 line
Quoted 1 line · Tao Guo

gas in binutils(2.16.91) could not parse parentheses within macro parameters unless fully parenthesized, and this is a workaround to make old gas work without generating below errors:
arch/x86/kernel/entry_64.S: Assembler messages:
arch/x86/kernel/entry_64.S:387: Error: too many positional arguments arch/x86/kernel/entry_64.S:389: Error: too many positional arguments arch/x86/kernel/entry_64.S:390: Error: too many positional arguments arch/x86/kernel/entry_64.S:391: Error: too many positional arguments arch/x86/kernel/entry_64.S:392: Error: too many positional arguments arch/x86/kernel/entry_64.S:393: Error: too many positional arguments arch/x86/kernel/entry_64.S:394: Error: too many positional arguments

Quoted 5 lines
Quoted 1 line

This looks okay now to me, but I'm somewhat reluctant to formally ack it given that we know how broken those particular gas versions are.

Quoted 6 lines

Well, assuming Tao Guo test-booted a kernel build with this old GAS version, we could apply this patch on a best-effort basis - the changes don't look particularly ugly. If other, unacceptable uglies or fragilities come up then we might balk.

Agreed?

Fine with me.

Jan

#4 lore raw
In reply to Tao Guo
Quoted 12 lines · Tao Guo

gas in binutils(2.16.91) could not parse parentheses within macro parameters unless fully parenthesized, and this is a workaround to make old gas work without generating below errors:
arch/x86/kernel/entry_64.S: Assembler messages:
arch/x86/kernel/entry_64.S:387: Error: too many positional arguments arch/x86/kernel/entry_64.S:389: Error: too many positional arguments arch/x86/kernel/entry_64.S:390: Error: too many positional arguments arch/x86/kernel/entry_64.S:391: Error: too many positional arguments arch/x86/kernel/entry_64.S:392: Error: too many positional arguments arch/x86/kernel/entry_64.S:393: Error: too many positional arguments arch/x86/kernel/entry_64.S:394: Error: too many positional arguments

Quoted 5 lines
---
 arch/x86/include/asm/calling.h |   48 +++++++++++++++++++--------------------
 arch/x86/kernel/entry_64.S     |   20 ++++++++--------
 2 files changed, 33 insertions(+), 35 deletions(-)

<formletter>

This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read Documentation/stable_kernel_rules.txt for how to do this properly.

</formletter>

author
#5 lore raw
Quoted 19 lines · Greg KH
Quoted 12 lines · Tao Guo

gas in binutils(2.16.91) could not parse parentheses within macro parameters unless fully parenthesized, and this is a workaround to make old gas work without generating below errors:
arch/x86/kernel/entry_64.S: Assembler messages:
arch/x86/kernel/entry_64.S:387: Error: too many positional arguments arch/x86/kernel/entry_64.S:389: Error: too many positional arguments arch/x86/kernel/entry_64.S:390: Error: too many positional arguments arch/x86/kernel/entry_64.S:391: Error: too many positional arguments arch/x86/kernel/entry_64.S:392: Error: too many positional arguments arch/x86/kernel/entry_64.S:393: Error: too many positional arguments arch/x86/kernel/entry_64.S:394: Error: too many positional arguments

Quoted 5 lines
---
 arch/x86/include/asm/calling.h |   48 +++++++++++++++++++--------------------
 arch/x86/kernel/entry_64.S     |   20 ++++++++--------
 2 files changed, 33 insertions(+), 35 deletions(-)
Quoted 7 lines

<formletter>

This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read Documentation/stable_kernel_rules.txt for how to do this properly.

</formletter>

Thanks Greg, I just realized that I followed the old rules in an old Documentation/stable_kernel_rules.txt file. Since the patches for other stable branches will be a little different from this one, I will send them later to [email protected] after this patch gets accepted.

Thanks,
-Tao

#6 lore raw
Quoted 26 lines · Tao Guo
Quoted 25 lines · Greg KH
Quoted 12 lines · Tao Guo

gas in binutils(2.16.91) could not parse parentheses within macro parameters unless fully parenthesized, and this is a workaround to make old gas work without generating below errors:
arch/x86/kernel/entry_64.S: Assembler messages:
arch/x86/kernel/entry_64.S:387: Error: too many positional arguments arch/x86/kernel/entry_64.S:389: Error: too many positional arguments arch/x86/kernel/entry_64.S:390: Error: too many positional arguments arch/x86/kernel/entry_64.S:391: Error: too many positional arguments arch/x86/kernel/entry_64.S:392: Error: too many positional arguments arch/x86/kernel/entry_64.S:393: Error: too many positional arguments arch/x86/kernel/entry_64.S:394: Error: too many positional arguments

Quoted 5 lines
---
 arch/x86/include/asm/calling.h |   48 +++++++++++++++++++--------------------
 arch/x86/kernel/entry_64.S     |   20 ++++++++--------
 2 files changed, 33 insertions(+), 35 deletions(-)

<formletter>

This is not the correct way to submit patches for inclusion in the stable kernel tree. Please read Documentation/stable_kernel_rules.txt for how to do this properly.

Quoted 7 lines
Quoted 1 line

</formletter>

Thanks Greg, I just realized that I followed the old rules in an old Documentation/stable_kernel_rules.txt file. Since the patches for other stable branches will be a little different from this one, I will send them later to [email protected] after this patch gets accepted.

Please don't send this to -stale yet (or at all).

I have queued up the patch for v3.7, not even for v3.6. It needs more testing - old GAS users are probably better off having a non-building kernel than a subtly broken one. v3.7 and onwards stable kernels will have the fix - hopefully by the time it's released any more subtle bugs are found and fixed.

Thanks,

Ingo

#7 lore raw

[tip:x86/asm] x86_64: Work around old GAS bug

In reply to Tao Guo
Commit-ID:  1b2b23d8573076a587ed2081e0d2b69691079e0e
Gitweb:     http://git.kernel.org/tip/1b2b23d8573076a587ed2081e0d2b69691079e0e
Author:     Tao Guo <[email protected]>
AuthorDate: Wed, 26 Sep 2012 04:28:22 -0400
Committer:  Ingo Molnar <[email protected]>
CommitDate: Wed, 26 Sep 2012 13:35:32 +0200

x86_64: Work around old GAS bug

GAS in binutils(2.16.91) could not parse parentheses within macro parameters unless fully parenthesized, and this is a workaround to make old gas work without generating below errors:

arch/x86/kernel/entry_64.S: Assembler messages:
arch/x86/kernel/entry_64.S:387: Error: too many positional arguments arch/x86/kernel/entry_64.S:389: Error: too many positional arguments [...]

Cc Linus Torvalds <[email protected]>
Cc Andrew Morton <[email protected]>
[ Jan argues that these old GAS versions are fragile - which is so, but lets give them a chance. ]
---
 arch/x86/include/asm/calling.h |   48 +++++++++++++++++++--------------------
 arch/x86/kernel/entry_64.S     |   20 ++++++++--------
 2 files changed, 33 insertions(+), 35 deletions(-)
arch/x86/include/asm/calling.h +23 -25
index a9e3a74..7f8422a 100644
@@ -49,38 +49,36 @@ For 32-bit we have the following conventions - kernel is built with
 #include "dwarf2.h"
 
 /*
- * 64-bit system call stack frame layout defines and helpers, for
- * assembly code (note that the seemingly unnecessary parentheses
- * are to prevent cpp from inserting spaces in expressions that get
- * passed to macros):
+ * 64-bit system call stack frame layout defines and helpers,
+ * for assembly code:
  */
 
-#define R15		  (0)
-#define R14		  (8)
-#define R13		 (16)
-#define R12		 (24)
-#define RBP		 (32)
-#define RBX		 (40)
+#define R15		  0
+#define R14		  8
+#define R13		 16
+#define R12		 24
+#define RBP		 32
+#define RBX		 40
 
 /* arguments: interrupts/non tracing syscalls only save up to here: */
-#define R11		 (48)
-#define R10		 (56)
-#define R9		 (64)
-#define R8		 (72)
-#define RAX		 (80)
-#define RCX		 (88)
-#define RDX		 (96)
-#define RSI		(104)
-#define RDI		(112)
-#define ORIG_RAX	(120)       /* + error_code */
+#define R11		 48
+#define R10		 56
+#define R9		 64
+#define R8		 72
+#define RAX		 80
+#define RCX		 88
+#define RDX		 96
+#define RSI		104
+#define RDI		112
+#define ORIG_RAX	120       /* + error_code */
 /* end of arguments */
 
 /* cpu exception frame or undefined in case of fast syscall: */
-#define RIP		(128)
-#define CS		(136)
-#define EFLAGS		(144)
-#define RSP		(152)
-#define SS		(160)
+#define RIP		128
+#define CS		136
+#define EFLAGS		144
+#define RSP		152
+#define SS		160
 
 #define ARGOFFSET	R11
 #define SWFRAME		ORIG_RAX
arch/x86/kernel/entry_64.S +10 -10
index b1dac12..2c67061 100644
@@ -342,15 +342,15 @@ ENDPROC(native_usergs_sysret64)
 	.macro SAVE_ARGS_IRQ
 	cld
 	/* start from rbp in pt_regs and jump over */
-	movq_cfi rdi, RDI-RBP
-	movq_cfi rsi, RSI-RBP
-	movq_cfi rdx, RDX-RBP
-	movq_cfi rcx, RCX-RBP
-	movq_cfi rax, RAX-RBP
-	movq_cfi  r8,  R8-RBP
-	movq_cfi  r9,  R9-RBP
-	movq_cfi r10, R10-RBP
-	movq_cfi r11, R11-RBP
+	movq_cfi rdi, (RDI-RBP)
+	movq_cfi rsi, (RSI-RBP)
+	movq_cfi rdx, (RDX-RBP)
+	movq_cfi rcx, (RCX-RBP)
+	movq_cfi rax, (RAX-RBP)
+	movq_cfi  r8,  (R8-RBP)
+	movq_cfi  r9,  (R9-RBP)
+	movq_cfi r10, (R10-RBP)
+	movq_cfi r11, (R11-RBP)
 
 	/* Save rbp so that we can unwind from get_irq_regs() */
 	movq_cfi rbp, 0
@@ -384,7 +384,7 @@ ENDPROC(native_usergs_sysret64)
 	.endm
 
 ENTRY(save_rest)
-	PARTIAL_FRAME 1 REST_SKIP+8
+	PARTIAL_FRAME 1 (REST_SKIP+8)
 	movq 5*8+16(%rsp), %r11	/* save return address */
 	movq_cfi rbx, RBX+16
 	movq_cfi rbp, RBP+16