Skip to contentSkip to conversation

x86/head_32: Fix overflow warning with 32-bit binutils

PATCH In review Borislav Petkov 2 participants 5 messages Jun 19, 2015 x86

lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

PATCH 1/1 x86/head_32: Fix overflow warning with 32-bit binutils

From: Borislav Petkov <[email protected]>

When building the kernel with 32-bit binutils built with support only for the i386 target, we get the following warning:

arch/x86/kernel/head_32.S:66: Warning: shift count out of range (32 is not between 0 and 31)

The problem is that in that case, binutils' internal type representation is 32-bit wide and the shift range overflows.

In order to fix this, manipulate the shift expression which creates the 4GiB constant to not overflow the shift count.

---
 arch/x86/kernel/head_32.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/head_32.S +2 -2
index 53eeb226657c..c601d1de5ae5 100644
@@ -63,8 +63,8 @@
 #endif
 
 /* Number of possible pages in the lowmem region */
-LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
-	
+LOWMEM_PAGES = (((2<<31) - __PAGE_OFFSET) >> PAGE_SHIFT)
+
 /* Enough space to fit pagetables for the low memory linear map */
 MAPPING_BEYOND_END = PAGE_TABLE_SIZE(LOWMEM_PAGES) << PAGE_SHIFT
 
Signature · 1 line
2.3.5
#1 lore raw
Quoted 25 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

When building the kernel with 32-bit binutils built with support only for the i386 target, we get the following warning:

arch/x86/kernel/head_32.S:66: Warning: shift count out of range (32 is not between 0 and 31)

The problem is that in that case, binutils' internal type representation is 32-bit wide and the shift range overflows.

In order to fix this, manipulate the shift expression which creates the 4GiB constant to not overflow the shift count.

---
 arch/x86/kernel/head_32.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/head_32.S +0 -0
index 53eeb226657c..c601d1de5ae5 100644

arch/x86/kernel/head_32.S line 67

Quoted 7 lines
arch/x86/kernel/head_32.S +2 -2
@@ -63,8 +63,8 @@
 #endif
 
 /* Number of possible pages in the lowmem region */
-LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
-	
+LOWMEM_PAGES = (((2<<31) - __PAGE_OFFSET) >> PAGE_SHIFT)
+

Hm, so if internally GAS uses 64-bit types, couldn't we 'make sure' it's a 64-bit type, by using something like 31LL? Assuming GAS understands that?

Or if the internal representation is 32 bits, then 2<<31 is just a fancy way of saying '0', right?

So this could be written as:

LOWMEM_PAGES = (-__PAGE_OFFSET >> PAGE_SHIFT)

or:

LOWMEM_PAGES = ((0 - __PAGE_OFFSET) >> PAGE_SHIFT)

right?

Or did it get it all wrong?

Thanks,

Ingo

author maintainer
#2 lore raw
Quoted 30 lines · Ingo Molnar
Quoted 27 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

When building the kernel with 32-bit binutils built with support only for the i386 target, we get the following warning:

arch/x86/kernel/head_32.S:66: Warning: shift count out of range (32 is not between 0 and 31)

The problem is that in that case, binutils' internal type representation is 32-bit wide and the shift range overflows.

In order to fix this, manipulate the shift expression which creates the 4GiB constant to not overflow the shift count.

---
 arch/x86/kernel/head_32.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/head_32.S +0 -0
index 53eeb226657c..c601d1de5ae5 100644
@@ -63,8 +63,8 @@
 #endif
 
Quoted 8 lines

arch/x86/kernel/head_32.S line 67

Quoted 5 lines
arch/x86/kernel/head_32.S +2 -2
 /* Number of possible pages in the lowmem region */
-LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
-	
+LOWMEM_PAGES = (((2<<31) - __PAGE_OFFSET) >> PAGE_SHIFT)
+

Hm, so if internally GAS uses 64-bit types, couldn't we 'make sure' it's a 64-bit type, by using something like 31LL? Assuming GAS understands that?

I don't think it does.

This fix is only when gas is compiled with the i386 target which uses solely 32-bit sized types for internal representation. The warning won't fire on gas built with multiple targets support even if you build with -m32.

Quoted 5 lines

Or if the internal representation is 32 bits, then 2<<31 is just a fancy way of saying '0', right?

So this could be written as:

Quoted 7 lines

LOWMEM_PAGES = (-__PAGE_OFFSET >> PAGE_SHIFT)

or:

LOWMEM_PAGES = ((0 - __PAGE_OFFSET) >> PAGE_SHIFT)

right?

Yes, you can do that only when the internal representation is a 32-bit type. If it is not and you still do an -m32 build, you then want the 4Gib value there and not a 0:

arch/x86/kernel/head_32.S: Assembler messages:
arch/x86/kernel/head_32.S:227: Error: value of 18014395285110787 too large for field of 4 bytes at 146 make[2]: *** [arch/x86/kernel/head_32.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [arch/x86/kernel] Error 2
make: *** [arch/x86] Error 2
make: *** Waiting for unfinished jobs....

Signature · 5 lines
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
#3 lore raw
Quoted 40 lines · Borislav Petkov
Quoted 30 lines · Ingo Molnar
Quoted 27 lines · Borislav Petkov

From: Borislav Petkov <[email protected]>

When building the kernel with 32-bit binutils built with support only for the i386 target, we get the following warning:

arch/x86/kernel/head_32.S:66: Warning: shift count out of range (32 is not between 0 and 31)

The problem is that in that case, binutils' internal type representation is 32-bit wide and the shift range overflows.

In order to fix this, manipulate the shift expression which creates the 4GiB constant to not overflow the shift count.

---
 arch/x86/kernel/head_32.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/kernel/head_32.S +0 -0
index 53eeb226657c..c601d1de5ae5 100644
@@ -63,8 +63,8 @@
 #endif
 
Quoted 8 lines

arch/x86/kernel/head_32.S line 67

Quoted 5 lines
arch/x86/kernel/head_32.S +2 -2
 /* Number of possible pages in the lowmem region */
-LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
-	
+LOWMEM_PAGES = (((2<<31) - __PAGE_OFFSET) >> PAGE_SHIFT)
+

Hm, so if internally GAS uses 64-bit types, couldn't we 'make sure' it's a 64-bit type, by using something like 31LL? Assuming GAS understands that?

Quoted 5 lines

I don't think it does.

This fix is only when gas is compiled with the i386 target which uses solely 32-bit sized types for internal representation. The warning won't fire on gas built with multiple targets support even if you build with -m32.

Ugh, nasty.

Quoted 11 lines
Quoted 11 lines

Or if the internal representation is 32 bits, then 2<<31 is just a fancy way of saying '0', right?

So this could be written as:

LOWMEM_PAGES = (-__PAGE_OFFSET >> PAGE_SHIFT)

or:

LOWMEM_PAGES = ((0 - __PAGE_OFFSET) >> PAGE_SHIFT)

Quoted 8 lines
Quoted 1 line

right?

Yes, you can do that only when the internal representation is a 32-bit type. If it is not and you still do an -m32 build, you then want the 4Gib value there and not a 0:

arch/x86/kernel/head_32.S: Assembler messages:
arch/x86/kernel/head_32.S:227: Error: value of 18014395285110787 too large for field of 4 bytes at 146

Grumble. I guess the workaround is OK then because I cannot think of any cleaner solution - but I'd suggest to put a comment there at minimum, to explain what it's about.

... and chances are that GAS might start warning about 2<<31 in the future as well.

Thanks,

Ingo
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in Please read the FAQ at http://www.tux.org/lkml/

author maintainer
#4 lore raw
Quoted 6 lines · Ingo Molnar

Grumble. I guess the workaround is OK then because I cannot think of any cleaner solution - but I'd suggest to put a comment there at minimum, to explain what it's about.

... and chances are that GAS might start warning about 2<<31 in the future as well.

Reportedly it won't because it'll wrap around to 0 and that is fine...

Anyway, here's v2:

---
From: Borislav Petkov <[email protected]>
Subject: [PATCH -v2] x86/head_32: Fix overflow warning with 32-bit binutils

When building the kernel with 32-bit binutils built with support only for the i386 target, we get the following warning:

arch/x86/kernel/head_32.S:66: Warning: shift count out of range (32 is not between 0 and 31)

The problem is that in that case, binutils' internal type representation is 32-bit wide and the shift range overflows.

In order to fix this, manipulate the shift expression which creates the 4GiB constant to not overflow the shift count.

---
 arch/x86/kernel/head_32.S | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)
arch/x86/kernel/head_32.S +10 -3
index 53eeb226657c..7e429c99c728 100644
@@ -62,9 +62,16 @@
 #define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
 #endif
 
-/* Number of possible pages in the lowmem region */
-LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
-	
+/*
+ * Number of possible pages in the lowmem region.
+ *
+ * We shift 2 by 31 instead of 1 by 32 to the left in order to avoid a
+ * gas warning about overflowing shift count when gas has been compiled
+ * with only a host target support using a 32-bit type for internal
+ * representation.
+ */
+LOWMEM_PAGES = (((2<<31) - __PAGE_OFFSET) >> PAGE_SHIFT)
+
 /* Enough space to fit pagetables for the low memory linear map */
 MAPPING_BEYOND_END = PAGE_TABLE_SIZE(LOWMEM_PAGES) << PAGE_SHIFT
 
Signature · 11 lines
2.3.5

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
Please read the FAQ at  http://www.tux.org/lkml/