i386: Use "movl main@GOT(%ebx), %eax" in start.S

Message ID 20171003141916.GA8915@gmail.com
State Committed
Commit 955774751b71c4bc94029dd541ad9d34634ec995
Headers

Commit Message

H.J. Lu Oct. 3, 2017, 2:19 p.m. UTC
  Don't use "leal main@GOTOFF(%ebx), %eax" since main may be in a
shared object.  Linker will convert "movl main@GOT(%ebx), %eax"
to "leal main@GOTOFF(%ebx), %eax" if main is defined locally.

Any comments?

H.J.
---
	* sysdeps/i386/start.S: Replace "leal main@GOT(%ebx), %eax" with
	"movl main@GOTOFF(%ebx), %eax".
---
 sysdeps/i386/start.S | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
  

Comments

Florian Weimer Oct. 3, 2017, 3:37 p.m. UTC | #1
* H. J. Lu:

> Don't use "leal main@GOTOFF(%ebx), %eax" since main may be in a
> shared object.  Linker will convert "movl main@GOT(%ebx), %eax"
> to "leal main@GOTOFF(%ebx), %eax" if main is defined locally.
>
> Any comments?

Would it be worthwhile to add a test for this which is not
architecture-specific?
  
H.J. Lu Oct. 3, 2017, 10:45 p.m. UTC | #2
On 10/3/17, Florian Weimer <fw@deneb.enyo.de> wrote:
> * H. J. Lu:
>
>> Don't use "leal main@GOTOFF(%ebx), %eax" since main may be in a
>> shared object.  Linker will convert "movl main@GOT(%ebx), %eax"
>> to "leal main@GOTOFF(%ebx), %eax" if main is defined locally.
>>
>> Any comments?
>
> Would it be worthwhile to add a test for this which is not
> architecture-specific?
>

Yes, a patch is here:

https://sourceware.org/ml/libc-alpha/2017-10/msg00104.html
  
H.J. Lu Oct. 4, 2017, 12:44 a.m. UTC | #3
On 10/3/17, H.J. Lu <hjl.tools@gmail.com> wrote:
> On 10/3/17, Florian Weimer <fw@deneb.enyo.de> wrote:
>> * H. J. Lu:
>>
>>> Don't use "leal main@GOTOFF(%ebx), %eax" since main may be in a
>>> shared object.  Linker will convert "movl main@GOT(%ebx), %eax"
>>> to "leal main@GOTOFF(%ebx), %eax" if main is defined locally.
>>>
>>> Any comments?
>>
>> Would it be worthwhile to add a test for this which is not
>> architecture-specific?
>>
>
> Yes, a patch is here:
>
> https://sourceware.org/ml/libc-alpha/2017-10/msg00104.html
>
>

I am checking it in.
  

Patch

diff --git a/sysdeps/i386/start.S b/sysdeps/i386/start.S
index 375a93c15a..916fcd2f9a 100644
--- a/sysdeps/i386/start.S
+++ b/sysdeps/i386/start.S
@@ -99,8 +99,11 @@  _start:
 	pushl main@GOT(%ebx)
 # else
 	/* Avoid relocation in static PIE since _start is called before
-	   it is relocated.  */
-	leal main@GOTOFF(%ebx), %eax
+	   it is relocated.  Don't use "leal main@GOTOFF(%ebx), %eax"
+	   since main may be in a shared object.  Linker will convert
+	   "movl main@GOT(%ebx), %eax" to "leal main@GOTOFF(%ebx), %eax"
+	   if main is defined locally.  */
+	movl main@GOT(%ebx), %eax
 	pushl %eax
 # endif