Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004414OCamlOCaml generalpublic2007-10-10 03:472013-09-04 17:53
Reportergordonhenriksen 
Assigned To 
PrioritynormalSeverityfeatureReproducibilityalways
StatusacknowledgedResolutionopen 
PlatformOSOS Version
Product Version3.10+dev 
Target VersionFixed in Version 
Summary0004414: ocamlopt places symbols interior to statically allocated 'value's
DescriptionFor statically allocated 'value's, ocamlopt places symbols interior to the objects they identify--specifically, the symbol lies after the object header. For instance, a string constant is emitted as such (x86):

        ; Existing behavior
        .data
        .long 2300 ; wosize=2, color=0, tag=string
_camlExample__1:
        .ascii "Hello"
        .space 2
        .byte 2 ; = (wosize*size_addr)-(strlen+1)

This is convenient in that it provides symbols which can be directly used as 'value's. However, it prevents applying dead stripping to the compiled code since the linker will incorrectly attribute the object header to the preceding symbol.
Additional InformationThe attached patch fixes the above problem by moving the symbols from the "value" position to the "header pointer" position. Referring to the same example as above, with this patch ocamlopt will emit:

        ; Behavior after patch
        .data
_camlExample__1:
        .long 2300 ; wosize=2, color=0, tag=string
        .ascii "Hello"
        .space 2
        .byte 2 ; = (wosize*size_addr)-(strlen+1)

In assembly and within the runtime, references to statically allocated objects are changed to use symbol+displacement references instead of bare symbol references. Here's an example of that change from the startup file:

        ; Existing behavior
        .data
        .globl _caml_exn_Out_of_memory
        .long 1024
_caml_exn_Out_of_memory:
        .long L100002
        .long 4348
L100002:
        .ascii "Out_of_memory"
        .space 2
        .byte 2
        .globl _caml_bucket_Out_of_memory
        .long 1024
_caml_bucket_Out_of_memory:
        .long _caml_exn_Out_of_memory

        ; Behavior after patch
        .data
        .globl _caml_exn_Out_of_memory
_caml_exn_Out_of_memory:
        .long 1024
        .long L100002 + 4
L100002:
        .long 4348
        .ascii "Out_of_memory"
        .space 2
        .byte 2
        .globl _caml_bucket_Out_of_memory
_caml_bucket_Out_of_memory:
        .long 1024
        .long _caml_exn_Out_of_memory + 4

References from code are modified similarly. Since the linker performs these displacement calculations, there is no runtime cost associated with this change.

This change should be binary compatible with compiled C extensions. However, it does break binary compatibility for ocamlopt output (obviously) and with the runtime (see asmrun/fail.c).

The patch is based on CVS HEAD as of 2007-10-10 01:08:08 UTC. It has been tested on Darwin x86 and PowerPC, primarily by make opt.opt, but also with the test directory (for whatever that's worth). Other architectures have been updated, but not tested (or even compiled!). However, the architecture-specific changes are both trivial and mechanical, so this shouldn't be much of a problem.

Caveats:
- I have observed that after the patch is applied, the i386 instruction selector occasionally will emit lea;movl instead of a simple movl as before the patch.
- In one instance only, I observed that the change introduced a seemingly unnecessary register copy. I have not scrutinized the PowerPC codegen in that level of detail.

With this change, it would be possible to move static exceptions from the startup assembly into the runtime. The only problem in doing so would be encoding Ocaml strings in C.
Tagspatch
Attached Filespatch file icon symbol-displacement.patch [^] (25,349 bytes) 2007-10-10 03:47 [Show Content]

- Relationships

-  Notes
There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2007-10-10 03:47 gordonhenriksen New Issue
2007-10-10 03:47 gordonhenriksen File Added: symbol-displacement.patch
2007-11-10 14:12 xleroy Status new => acknowledged
2013-09-04 17:53 doligez Tag Attached: patch


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker