Google Groups Home Help | Sign in
THREADED_CODE: Why CODE32 defined on x86-64?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  4 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Richard Jones  
View profile
 More options Nov 16 2005, 10:05 am
Newsgroups: fa.caml
From: Richard Jones <r...@annexia.org>
Date: Wed, 16 Nov 2005 15:05:42 UTC
Local: Wed, Nov 16 2005 10:05 am
Subject: [Caml-list] THREADED_CODE: Why CODE32 defined on x86-64?

Why is CODE32 defined on the x86-64 architecture?  This architecture
has 64 bit pointers, and it seems like it's only by luck that the
bytecode interpreter normally works.

In particular, if you have the interpreter in a shared library, or (I
assume) address-space randomization, then the jump table is located
above the 4GB boundary, and the bytecode interpreter segfaults as soon
as it tries to jump to the first instruction.

I had to apply the following patch to allow the bytecode interpreter
to work in a shared library:

--- ocaml-3.09.0.orig/configure 2005-09-24 10:19:09.000000000 +0100
+++ ocaml-3.09.0/configure      2005-11-16 14:59:56.000000000 +0000
@@ -291,9 +291,7 @@
     exe=".exe"
     ostype="Cygwin";;
   gcc*,x86_64-*-linux*)
-    bytecccompopts="-fno-defer-pop $gcc_warnings"
-    # Tell gcc that we can use 32-bit code addresses for threaded code
-    echo "#define ARCH_CODE32" >> m.h;;
+    bytecccompopts="-fno-defer-pop $gcc_warnings";;
   gcc*)
     bytecccompopts="-fno-defer-pop $gcc_warnings";;
 esac

Rich.

--
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Xavier Leroy  
View profile
 More options Nov 16 2005, 10:26 am
Newsgroups: fa.caml
From: Xavier Leroy <Xavier.Le...@inria.fr>
Date: Wed, 16 Nov 2005 15:26:36 UTC
Local: Wed, Nov 16 2005 10:26 am
Subject: Re: [Caml-list] THREADED_CODE: Why CODE32 defined on x86-64?

> Why is CODE32 defined on the x86-64 architecture?  This architecture
> has 64 bit pointers, and it seems like it's only by luck that the
> bytecode interpreter normally works.

No, it's not by luck: the x86-64 ABI defines several "code models",
one of which -- the "small code model" -- guarantees that code and
static data is in the lower 2G of the address space, and is the
default for gcc (and I suspect other compilers as well).

I would have expected the dynamic loader to implement the small model
like the static linker does, but from what you say it's not the case.

- Xavier Leroy

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Jones  
View profile
 More options Nov 16 2005, 11:18 am
Newsgroups: fa.caml
From: Richard Jones <r...@annexia.org>
Date: Wed, 16 Nov 2005 16:18:22 UTC
Local: Wed, Nov 16 2005 11:18 am
Subject: Re: [Caml-list] THREADED_CODE: Why CODE32 defined on x86-64?

On Wed, Nov 16, 2005 at 04:21:23PM +0100, Xavier Leroy wrote:
> > Why is CODE32 defined on the x86-64 architecture?  This architecture
> > has 64 bit pointers, and it seems like it's only by luck that the
> > bytecode interpreter normally works.

> No, it's not by luck: the x86-64 ABI defines several "code models",
> one of which -- the "small code model" -- guarantees that code and
> static data is in the lower 2G of the address space, and is the
> default for gcc (and I suspect other compilers as well).

> I would have expected the dynamic loader to implement the small model
> like the static linker does, but from what you say it's not the case.

Thanks for looking into this.

It's definitely necessary for the dynamically linked code.  See below
for /proc/*/maps for an Apache process which contains a working
instance of mod_caml.so and the bytecode interpreter libcamlrun.so
recompiled with CODE32 undefined.

It might also be necessary if someone started to do address space
randomization for example using PIE-compiled binaries, but I'm not
certain about that.

Rich.

00400000-0044a000 r-xp 00000000 08:01 10190863                           /usr/sbin/apache
00549000-00551000 rw-p 00049000 08:01 10190863                           /usr/sbin/apache
00551000-00720000 rw-p 00551000 00:00 0                                  [heap]
2aaaaaaab000-2aaaaaac1000 r-xp 00000000 08:01 13221907                   /lib/ld-2.3.5.so
2aaaaaac1000-2aaaaaac5000 rw-p 2aaaaaac1000 00:00 0
2aaaaaac7000-2aaaaab41000 rw-p 2aaaaaac7000 00:00 0
2aaaaabc1000-2aaaaabc2000 rw-p 00016000 08:01 13221907                   /lib/ld-2.3.5.so
2aaaaabc2000-2aaaaac47000 r-xp 00000000 08:01 13221916                   /lib/libm-2.3.5.so
2aaaaac47000-2aaaaad46000 ---p 00085000 08:01 13221916                   /lib/libm-2.3.5.so
2aaaaad46000-2aaaaad47000 rw-p 00084000 08:01 13221916                   /lib/libm-2.3.5.so
2aaaaad47000-2aaaaad57000 r-xp 00000000 08:01 13221926                   /lib/libpthread-2.3.5.so
2aaaaad57000-2aaaaae57000 ---p 00010000 08:01 13221926                   /lib/libpthread-2.3.5.so
2aaaaae57000-2aaaaae58000 rw-p 00010000 08:01 13221926                   /lib/libpthread-2.3.5.so
2aaaaae58000-2aaaaae5c000 rw-p 2aaaaae58000 00:00 0
2aaaaae5c000-2aaaaae61000 r-xp 00000000 08:01 13221914                   /lib/libcrypt-2.3.5.so
2aaaaae61000-2aaaaaf60000 ---p 00005000 08:01 13221914                   /lib/libcrypt-2.3.5.so
2aaaaaf60000-2aaaaaf61000 rw-p 00004000 08:01 13221914                   /lib/libcrypt-2.3.5.so
2aaaaaf61000-2aaaaaf8f000 rw-p 2aaaaaf61000 00:00 0
2aaaaaf8f000-2aaaab070000 r-xp 00000000 08:01 1347676                    /usr/lib/libdb-4.2.so
2aaaab070000-2aaaab170000 ---p 000e1000 08:01 1347676                    /usr/lib/libdb-4.2.so
2aaaab170000-2aaaab174000 rw-p 000e1000 08:01 1347676                    /usr/lib/libdb-4.2.so
2aaaab174000-2aaaab175000 rw-p 2aaaab174000 00:00 0
2aaaab175000-2aaaab194000 r-xp 00000000 08:01 1349826                    /usr/lib/libexpat.so.1.0.0
2aaaab194000-2aaaab293000 ---p 0001f000 08:01 1349826                    /usr/lib/libexpat.so.1.0.0
2aaaab293000-2aaaab298000 rw-p 0001e000 08:01 1349826                    /usr/lib/libexpat.so.1.0.0
2aaaab298000-2aaaab29a000 r-xp 00000000 08:01 13221915                   /lib/libdl-2.3.5.so
2aaaab29a000-2aaaab399000 ---p 00002000 08:01 13221915                   /lib/libdl-2.3.5.so
2aaaab399000-2aaaab39a000 rw-p 00001000 08:01 13221915                   /lib/libdl-2.3.5.so
2aaaab39a000-2aaaab4c8000 r-xp 00000000 08:01 13221913                   /lib/libc-2.3.5.so
2aaaab4c8000-2aaaab5c7000 ---p 0012e000 08:01 13221913                   /lib/libc-2.3.5.so
2aaaab5c7000-2aaaab5cd000 rw-p 0012d000 08:01 13221913                   /lib/libc-2.3.5.so
2aaaab5cd000-2aaaab5d3000 rw-p 2aaaab5cd000 00:00 0
2aaaab5d3000-2aaaab5d7000 r-xp 00000000 08:01 1460484                    /usr/lib/apache/1.3/mod_log_config.so
2aaaab5d7000-2aaaab6d6000 ---p 00004000 08:01 1460484                    /usr/lib/apache/1.3/mod_log_config.so
2aaaab6d6000-2aaaab6d7000 rw-p 00003000 08:01 1460484                    /usr/lib/apache/1.3/mod_log_config.so
2aaaab6d7000-2aaaab6dc000 r-xp 00000000 08:01 1460487                    /usr/lib/apache/1.3/mod_mime_magic.so
2aaaab6dc000-2aaaab7db000 ---p 00005000 08:01 1460487                    /usr/lib/apache/1.3/mod_mime_magic.so
2aaaab7db000-2aaaab7dc000 rw-p 00004000 08:01 1460487                    /usr/lib/apache/1.3/mod_mime_magic.so
2aaaab7dc000-2aaaab7df000 r-xp 00000000 08:01 1460488                    /usr/lib/apache/1.3/mod_mime.so
2aaaab7df000-2aaaab8df000 ---p 00003000 08:01 1460488                    /usr/lib/apache/1.3/mod_mime.so
2aaaab8df000-2aaaab8e0000 rw-p 00003000 08:01 1460488                    /usr/lib/apache/1.3/mod_mime.so
2aaaab8e0000-2aaaab8e6000 r-xp 00000000 08:01 1460489                    /usr/lib/apache/1.3/mod_negotiation.so
2aaaab8e6000-2aaaab9e5000 ---p 00006000 08:01 1460489                    /usr/lib/apache/1.3/mod_negotiation.so
2aaaab9e5000-2aaaab9e6000 rw-p 00005000 08:01 1460489                    /usr/lib/apache/1.3/mod_negotiation.so
2aaaab9e6000-2aaaab9ea000 r-xp 00000000 08:01 1460490                    /usr/lib/apache/1.3/mod_status.so
2aaaab9ea000-2aaaabae9000 ---p 00004000 08:01 1460490                    /usr/lib/apache/1.3/mod_status.so
2aaaabae9000-2aaaabaea000 rw-p 00003000 08:01 1460490                    /usr/lib/apache/1.3/mod_status.so
2aaaabaea000-2aaaabaf1000 r-xp 00000000 08:01 1460493                    /usr/lib/apache/1.3/mod_autoindex.so
2aaaabaf1000-2aaaabbf1000 ---p 00007000 08:01 1460493                    /usr/lib/apache/1.3/mod_autoindex.so
2aaaabbf1000-2aaaabbf2000 rw-p 00007000 08:01 1460493                    /usr/lib/apache/1.3/mod_autoindex.so
2aaaabbf2000-2aaaabbf4000 r-xp 00000000 08:01 1460494                    /usr/lib/apache/1.3/mod_dir.so
2aaaabbf4000-2aaaabcf3000 ---p 00002000 08:01 1460494                    /usr/lib/apache/1.3/mod_dir.so
2aaaabcf3000-2aaaabcf4000 rw-p 00001000 08:01 1460494                    /usr/lib/apache/1.3/mod_dir.so
2aaaabcf4000-2aaaabcf7000 r-xp 00000000 08:01 1460495                    /usr/lib/apache/1.3/mod_cgi.so
2aaaabcf7000-2aaaabdf6000 ---p 00003000 08:01 1460495                    /usr/lib/apache/1.3/mod_cgi.so
2aaaabdf6000-2aaaabdf7000 rw-p 00002000 08:01 1460495                    /usr/lib/apache/1.3/mod_cgi.so
2aaaabdf7000-2aaaabdf9000 r-xp 00000000 08:01 1460500                    /usr/lib/apache/1.3/mod_userdir.so
2aaaabdf9000-2aaaabef8000 ---p 00002000 08:01 1460500                    /usr/lib/apache/1.3/mod_userdir.so
2aaaabef8000-2aaaabef9000 rw-p 00001000 08:01 1460500                    /usr/lib/apache/1.3/mod_userdir.so
2aaaabef9000-2aaaabefb000 r-xp 00000000 08:01 1460501                    /usr/lib/apache/1.3/mod_alias.so
2aaaabefb000-2aaaabffb000 ---p 00002000 08:01 1460501                    /usr/lib/apache/1.3/mod_alias.so
2aaaabffb000-2aaaabffc000 rw-p 00002000 08:01 1460501                    /usr/lib/apache/1.3/mod_alias.so
2aaaabffc000-2aaaac008000 r-xp 00000000 08:01 1460502                    /usr/lib/apache/1.3/mod_rewrite.so
2aaaac008000-2aaaac108000 ---p 0000c000 08:01 1460502                    /usr/lib/apache/1.3/mod_rewrite.so
2aaaac108000-2aaaac109000 rw-p 0000c000 08:01 1460502                    /usr/lib/apache/1.3/mod_rewrite.so
2aaaac109000-2aaaac10b000 r-xp 00000000 08:01 1460503                    /usr/lib/apache/1.3/mod_access.so
2aaaac10b000-2aaaac20a000 ---p 00002000 08:01 1460503                    /usr/lib/apache/1.3/mod_access.so
2aaaac20a000-2aaaac20b000 rw-p 00001000 08:01 1460503                    /usr/lib/apache/1.3/mod_access.so
2aaaac20b000-2aaaac20d000 r-xp 00000000 08:01 1460504                    /usr/lib/apache/1.3/mod_auth.so
2aaaac20d000-2aaaac30d000 ---p 00002000 08:01 1460504                    /usr/lib/apache/1.3/mod_auth.so
2aaaac30d000-2aaaac30e000 rw-p 00002000 08:01 1460504                    /usr/lib/apache/1.3/mod_auth.so
2aaaac30e000-2aaaac310000 r-xp 00000000 08:01 1460510                    /usr/lib/apache/1.3/mod_expires.so
2aaaac310000-2aaaac40f000 ---p 00002000 08:01 1460510                    /usr/lib/apache/1.3/mod_expires.so
2aaaac40f000-2aaaac410000 rw-p 00001000 08:01 1460510                    /usr/lib/apache/1.3/mod_expires.so
2aaaac410000-2aaaac412000 r-xp 00000000 08:01 1460515                    /usr/lib/apache/1.3/mod_setenvif.so
2aaaac412000-2aaaac511000 ---p 00002000 08:01 1460515                    /usr/lib/apache/1.3/mod_setenvif.so
2aaaac511000-2aaaac512000 rw-p 00001000 08:01 1460515                    /usr/lib/apache/1.3/mod_setenvif.so
2aaaac512000-2aaaac532000 r-xp 00000000 08:01 1460823                    /usr/lib/apache/1.3/mod_caml.so
2aaaac532000-2aaaac632000 ---p 00020000 08:01 1460823                    /usr/lib/apache/1.3/mod_caml.so
2aaaac632000-2aaaac636000 rw-p 00020000 08:01 1460823                    /usr/lib/apache/1.3/mod_caml.so
2aaaac636000-2aaaac638000 rw-p 2aaaac636000 00:00 0
2aaaac64a000-2aaaac65b000 r-xp 00000000 08:01 1356423                    /usr/lib/libpcre.so.3.11.0
2aaaac65b000-2aaaac75b000 ---p 00011000 08:01 1356423                    /usr/lib/libpcre.so.3.11.0
2aaaac75b000-2aaaac772000 rw-p 00011000 08:01 1356423                    /usr/lib/libpcre.so.3.11.0
2aaaac772000-2aaaac798000 r-xp 00000000 08:01 1738105                    /usr/lib/ocaml/3.08.3/libcamlrun.so
2aaaac798000-2aaaac898000 ---p 00026000 08:01 1738105                    /usr/lib/ocaml/3.08.3/libcamlrun.so
2aaaac898000-2aaaac89a000 rw-p 00026000 08:01 1738105                    /usr/lib/ocaml/3.08.3/libcamlrun.so
2aaaac89a000-2aaaac89d000 rw-p 2aaaac89a000 00:00 0
2aaaac89d000-2aaaac8ea000 r-xp 00000000 08:01 13221951                   /lib/libncurses.so.5.4
2aaaac8ea000-2aaaac9ea000 ---p 0004d000 08:01 13221951                   /lib/libncurses.so.5.4
2aaaac9ea000-2aaaac9f8000 rw-p 0004d000 08:01 13221951                
...

read more »


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
skaller  
View profile
 More options Nov 16 2005, 2:01 pm
Newsgroups: fa.caml
From: skaller <skal...@users.sourceforge.net>
Date: Wed, 16 Nov 2005 19:01:14 UTC
Local: Wed, Nov 16 2005 2:01 pm
Subject: Re: [Caml-list] THREADED_CODE: Why CODE32 defined on x86-64?

On Wed, 2005-11-16 at 16:21 +0100, Xavier Leroy wrote:
> I would have expected the dynamic loader to implement the small model
> like the static linker does, but from what you say it's not the case.

The modelling constraints only apply to a statically
linked image. The reason is that the constraints allow
offsets for various instructions to 'fit' in the opcode.

Dynamically loaded *shared* libraries are accessed
indirectly via tables .. so it doesn't matter where
they're loaded.

--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net

_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google