User account creation filtered due to spam.

Bug 10355 - i386 regparm doco note on shlib use
Summary: i386 regparm doco note on shlib use
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.2
: P3 normal
Target Milestone: 3.3.1
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-04-08 22:26 UTC by user42
Modified: 2003-07-25 23:18 UTC (History)
1 user (show)

See Also:
Host: i386-pc-linux-gnu
Target: i386-pc-linux-gnu
Build: i386-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description user42 2003-04-08 22:26:00 UTC
The i386 regparm attribute is not good for functions in shared
libraries on some systems.  It'd be nice to have a warning about that
in the manual.

Release:
3.2.3 20030316 (Debian prerelease) (Debian testing/unstable)

Environment:
System: Linux blah 2.2.15 #1 Tue Apr 25 17:13:48 EST 2000 i586 unknown unknown GNU/Linux
Architecture: i586
	<machine, os, target, libraries (multiple lines)>
host: i386-pc-linux-gnu
build: i386-pc-linux-gnu
target: i386-pc-linux-gnu
configured with: ../src/configure -v --enable-languages=c,c++,java,f77,proto,pascal,objc,ada --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-gxx-include-dir=/usr/include/c++/3.2 --enable-shared --with-system-zlib --enable-nls --without-included-gettext --enable-__cxa_atexit --enable-clocale=gnu --enable-java-gc=boehm --enable-objc-gc i386-linux

How-To-Repeat:
On Solaris 8, the loader's lazy binding resolver code clobbers eax,
ecx and edx, in accordance with the standard calling conventions,
meaning bad values reach the first call to a regparm function.

Unformatted:
 --=-=-=
Comment 1 user42 2003-04-08 22:26:00 UTC
Fix:
I'd like to propose the few words below.  GLIBC and FreeBSD are the
only loaders I've had a close look at.  Very possibly other BSD
flavours are safe too.


--=-=-=
Content-Disposition: attachment; filename=extend.texi.regparm-plt.diff

--- extend.texi.~1.127.~	2003-03-27 09:10:43.000000000 +1000
+++ extend.texi	2003-04-09 08:17:25.000000000 +1000
@@ -2360,6 +2360,7 @@
 @code{local-dynamic}, @code{initial-exec} or @code{local-exec}.
 
 @item regparm (@var{number})
+@cindex @code{regparm} attribute
 @cindex functions that are passed arguments in registers on the 386
 On the Intel 386, the @code{regparm} attribute causes the compiler to
 pass up to @var{number} integer arguments in registers EAX,
@@ -2367,6 +2368,14 @@
 variable number of arguments will continue to be passed all of their
 arguments on the stack.
 
+Beware that on some ELF systems this attribute is unsuitable for
+global functions in shared libraries.  Lazy binding will send the
+first call via resolving code in the loader, which might assume EAX,
+EDX and ECX can be clobbered, as per the standard calling conventions.
+Solaris 8 is affected by this.  GNU systems with GLIBC 2.1 or higher,
+and FreeBSD, are believed to be safe though since the loaders there
+save all registers.
+
 @item stdcall
 @cindex functions that pop the argument stack on the 386
 On the Intel 386, the @code{stdcall} attribute causes the compiler to

--=-=-=--
Comment 2 Wolfgang Bangerth 2003-05-20 22:28:21 UTC
State-Changed-From-To: open->closed
State-Changed-Why: Patch committed. Thanks for your help!
    
    W.