caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: [Caml-list] THREADED_CODE: Why CODE32 defined on x86-64?
  2005-11-16 15:23 THREADED_CODE: Why CODE32 defined on x86-64? Richard Jones
@ 2005-11-16 15:21 ` Xavier Leroy
  2005-11-16 16:36   ` Richard Jones
  2005-11-16 18:55   ` skaller
  0 siblings, 2 replies; 4+ messages in thread
From: Xavier Leroy @ 2005-11-16 15:21 UTC (permalink / raw)
  To: Richard Jones; +Cc: caml-list, caml-bugs

> 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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* THREADED_CODE: Why CODE32 defined on x86-64?
@ 2005-11-16 15:23 Richard Jones
  2005-11-16 15:21 ` [Caml-list] " Xavier Leroy
  0 siblings, 1 reply; 4+ messages in thread
From: Richard Jones @ 2005-11-16 15:23 UTC (permalink / raw)
  To: caml-list; +Cc: caml-bugs


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] THREADED_CODE: Why CODE32 defined on x86-64?
  2005-11-16 15:21 ` [Caml-list] " Xavier Leroy
@ 2005-11-16 16:36   ` Richard Jones
  2005-11-16 18:55   ` skaller
  1 sibling, 0 replies; 4+ messages in thread
From: Richard Jones @ 2005-11-16 16:36 UTC (permalink / raw)
  To: Xavier Leroy; +Cc: caml-list

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                   /lib/libncurses.so.5.4
2aaaac9f8000-2aaaacb00000 rw-p 2aaaac9f8000 00:00 0 
2aaaacb00000-2aaaacb08000 r-xp 00000000 08:01 13221919                   /lib/libnss_compat-2.3.5.so
2aaaacb08000-2aaaacc08000 ---p 00008000 08:01 13221919                   /lib/libnss_compat-2.3.5.so
2aaaacc08000-2aaaacc09000 rw-p 00008000 08:01 13221919                   /lib/libnss_compat-2.3.5.so
2aaaacc09000-2aaaacc1d000 r-xp 00000000 08:01 13221918                   /lib/libnsl-2.3.5.so
2aaaacc1d000-2aaaacd1d000 ---p 00014000 08:01 13221918                   /lib/libnsl-2.3.5.so
2aaaacd1d000-2aaaacd1e000 rw-p 00014000 08:01 13221918                   /lib/libnsl-2.3.5.so
2aaaacd1e000-2aaaacd20000 rw-p 2aaaacd1e000 00:00 0 
2aaaacd20000-2aaaacd29000 r-xp 00000000 08:01 13221923                   /lib/libnss_nis-2.3.5.so
2aaaacd29000-2aaaace29000 ---p 00009000 08:01 13221923                   /lib/libnss_nis-2.3.5.so
2aaaace29000-2aaaace2a000 rw-p 00009000 08:01 13221923                   /lib/libnss_nis-2.3.5.so
2aaaace2a000-2aaaace35000 r-xp 00000000 08:01 13221921                   /lib/libnss_files-2.3.5.so
2aaaace35000-2aaaacf34000 ---p 0000b000 08:01 13221921                   /lib/libnss_files-2.3.5.so
2aaaacf34000-2aaaacf35000 rw-p 0000a000 08:01 13221921                   /lib/libnss_files-2.3.5.so
2aaaacf35000-2aaaacf39000 r-xp 00000000 08:01 1738272                    /usr/lib/ocaml/3.08.3/stublibs/dllnums.so
2aaaacf39000-2aaaad038000 ---p 00004000 08:01 1738272                    /usr/lib/ocaml/3.08.3/stublibs/dllnums.so
2aaaad038000-2aaaad039000 rw-p 00003000 08:01 1738272                    /usr/lib/ocaml/3.08.3/stublibs/dllnums.so
2aaaad039000-2aaaad158000 rw-p 2aaaad039000 00:00 0 
2aaaad158000-2aaaad15d000 r-xp 00000000 08:01 1739505                    /usr/lib/ocaml/3.08.3/stublibs/dllpostgresql_stubs.so
2aaaad15d000-2aaaad25d000 ---p 00005000 08:01 1739505                    /usr/lib/ocaml/3.08.3/stublibs/dllpostgresql_stubs.so
2aaaad25d000-2aaaad25e000 rw-p 00005000 08:01 1739505                    /usr/lib/ocaml/3.08.3/stublibs/dllpostgresql_stubs.so
2aaaad270000-2aaaad28f000 r-xp 00000000 08:01 1351627                    /usr/lib/libpq.so.4.0
2aaaad28f000-2aaaad38f000 ---p 0001f000 08:01 1351627                    /usr/lib/libpq.so.4.0
2aaaad38f000-2aaaad391000 rw-p 0001f000 08:01 1351627                    /usr/lib/libpq.so.4.0
2aaaad391000-2aaaad3c3000 r-xp 00000000 08:01 1352729                    /usr/lib/libssl.so.0.9.7
2aaaad3c3000-2aaaad4c3000 ---p 00032000 08:01 1352729                    /usr/lib/libssl.so.0.9.7
2aaaad4c3000-2aaaad4c8000 rw-p 00032000 08:01 1352729                    /usr/lib/libssl.so.0.9.7
2aaaad4c8000-2aaaad5e6000 r-xp 00000000 08:01 1352728                    /usr/lib/libcrypto.so.0.9.7
2aaaad5e6000-2aaaad6e5000 ---p 0011e000 08:01 1352728                    /usr/lib/libcrypto.so.0.9.7
2aaaad6e5000-2aaaad704000 rw-p 0011d000 08:01 1352728                    /usr/lib/libcrypto.so.0.9.7
2aaaad704000-2aaaad708000 rw-p 2aaaad704000 00:00 0 
2aaaad708000-2aaaad773000 r-xp 00000000 08:01 1350139                    /usr/lib/libkrb5.so.3.2
2aaaad773000-2aaaad872000 ---p 0006b000 08:01 1350139                    /usr/lib/libkrb5.so.3.2
2aaaad872000-2aaaad876000 rw-p 0006a000 08:01 1350139                    /usr/lib/libkrb5.so.3.2
2aaaad876000-2aaaad887000 r-xp 00000000 08:01 13221927                   /lib/libresolv-2.3.5.so
2aaaad887000-2aaaad987000 ---p 00011000 08:01 13221927                   /lib/libresolv-2.3.5.so
2aaaad987000-2aaaad988000 rw-p 00011000 08:01 13221927                   /lib/libresolv-2.3.5.so
2aaaad988000-2aaaad98b000 rw-p 2aaaad988000 00:00 0 
2aaaad98b000-2aaaad9ad000 r-xp 00000000 08:01 1350137                    /usr/lib/libk5crypto.so.3.0
2aaaad9ad000-2aaaadaad000 ---p 00022000 08:01 1350137                    /usr/lib/libk5crypto.so.3.0
2aaaadaad000-2aaaadaaf000 rw-p 00022000 08:01 1350137                    /usr/lib/libk5crypto.so.3.0
2aaaadaaf000-2aaaadab1000 r-xp 00000000 08:01 13221900                   /lib/libcom_err.so.2.1
2aaaadab1000-2aaaadbb0000 ---p 00002000 08:01 13221900                   /lib/libcom_err.so.2.1
2aaaadbb0000-2aaaadbb1000 rw-p 00001000 08:01 13221900                   /lib/libcom_err.so.2.1
2aaaadbb1000-2aaaaddc4000 rw-p 2aaaadbb1000 00:00 0 
2aaaaddc4000-2aaaadebd000 rw-s 00000000 00:07 221052962                  /SYSV00000000 (deleted)
7fffff918000-7fffff92e000 rw-p 7fffff918000 00:00 0                      [stack]
ffffffffff600000-ffffffffffe00000 ---p 00000000 00:00 0                  [vdso]


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


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Caml-list] THREADED_CODE: Why CODE32 defined on x86-64?
  2005-11-16 15:21 ` [Caml-list] " Xavier Leroy
  2005-11-16 16:36   ` Richard Jones
@ 2005-11-16 18:55   ` skaller
  1 sibling, 0 replies; 4+ messages in thread
From: skaller @ 2005-11-16 18:55 UTC (permalink / raw)
  To: Xavier Leroy; +Cc: Richard Jones, caml-bugs, caml-list

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


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-11-16 18:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-16 15:23 THREADED_CODE: Why CODE32 defined on x86-64? Richard Jones
2005-11-16 15:21 ` [Caml-list] " Xavier Leroy
2005-11-16 16:36   ` Richard Jones
2005-11-16 18:55   ` skaller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).