Skip to content

ocamlopt support for POWER/PowerPC in 64-bit mode and little-endian mode#225

Merged
bactrian merged 19 commits intotrunkfrom
ppc64
Aug 25, 2015
Merged

ocamlopt support for POWER/PowerPC in 64-bit mode and little-endian mode#225
bactrian merged 19 commits intotrunkfrom
ppc64

Conversation

@xavierleroy
Copy link
Copy Markdown
Contributor

Following up on bug report 6943, this pull request provides native-code compilation support for the POWER/PowerPC architecture in 64-bit mode, both in big-endian (ppc64 in Debian's classification) and in little-endian (ppc64le).

Summary of changes

Starting with the existing power port of ocamlopt, which supports PPC32/Linux, PPC32/MacOSX and PPC64/MacOSX, this PR:

  • Removes support for MacOSX (which no longer works on PowerPC machines) and historical remnants of a long-dead AIX port.
  • Updates the 32-bit code generator with partial GDB debugging support (.loc and .cfi directives), and @plt relocations for semi-position-independent code (working around the limited excursion of the "branch and link" instruction).
  • Updates the 64-bit code generator likewise.
  • Adds support for little-endian execution in addition to big-endian.
  • Adds support for the ELF PPC64 ABI version 1, as used in the ppc64 64-bit, big-endian configuration.
  • Adds support for the ELF PPC64 ABI version 2, as used in the ppc64le 64-bit, little-endian configuration.

Comparison with RedHat's ports

RedHat already provides OCaml ports for ppc64 and ppc64le, developed in-house and/or in cooperation with IBM. Those ports were an excellent source of inspiration for the proposed code, explaining some of the subtleties of the ELF PPC64 ABIs. The proposed code significantly departs from RedHat's on three points:

  • RedHat has 3 different architectures, in asmcomp/power, asmcomp/power64 and asmcomp/power64le, with copious duplication of code between these three directories. This is not maintainable in the long term. In contrast, the proposed code is one unified architecture, in asmcomp/power, and uses the "model" configuration variable to adapt between 32 and 64 bits, between big and little endian, and between the various ABIs. Code is factored out as much as possible.
  • RedHat's PPC64 ports work hard to maintain the standard shape of PPC64 stack frames, including the back link between frames. This comes at some costs in code complexity. The proposed code uses a simpler shape of stack frames, similar to the one used in other OCaml code generators, and without back links. Appropriate .cfi directives are generated to enable GDB to walk the call stack as usual.
  • RedHat's PPC64 ports do not use the bl function_symbol; nop idiom to call known OCaml functions, using more expensive indirect calls instead. (The idiom is specially optimized by the linker.) This is probably due to problems with tail calls. The proposed code solves these problems differently, using explicit saving and restoring of the TOC register r2, in a way that remains compatible with the idiom and its link-time optimization.

Status and testing

The new port, in its 3 configurations (ppc, ppc64, ppc64le), was tested under Debian 8.1, on a G5 PowerMac at Inria for the ppc and ppc64 configurations, and on a POWER8 virtual machine provided by RedHat Brno for the ppc64le configuration.

All tests from the OCaml test suite pass except one socket-related test that fails on the POWER8 VM, very probably because the VM is IPv6-only and the test is not IPv6-ready.

gprof-style profiling (ocamlopt -p) currently does not work on ppc64le, but it does not work with GCC either. I suspect a problem within Glibc, and reported it to Debian (http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=794222).

The 32 and 64be configurations were also successfully tested on the CompCert compiler.

Maintainability

As a member of the OCaml core dev team, I should be able to support this port in the medium to long term, provided

  • our 2005-vintage PowerMac G5 doesn't break (but those things are solidly built);
  • IBM and RedHat keep providing POWER8 VMs as part of their OpenPOWER programme.

I am looking into the possibility of adding the PowerMac G5 to our continuous integration system.

- Removed MacOS X support, long dead.
- Added support for PowerPC 64 bits, big-endian, ELF v1 ABI
  (tested, mostly works, some issues remain with marshaling of code pointers)
- Added support for PowerPC 64 bits, little-endian, ELF v2 ABI
  (completely untested)


git-svn-id: http://caml.inria.fr/svn/ocaml/branches/ppc64@16226 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
PPC: add some CFI directives and a bit of debug info.
testsuite/tests/asmcomp/power.S: update for PPC64le.


git-svn-id: http://caml.inria.fr/svn/ocaml/branches/ppc64@16227 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
…nk" (default) mode.

This is not absolutely necessary, since the dynamic loader is able to relocate non-plt "bl" instructions.  However, it avoids problems with direct "bl" instructions that overflow the limited excursion of this instruction (+/- 16 Mbytes).  Also, the static linker is clever enough to optimize @plt calls into normal calls when they are within the same static executable or the same DLL.  So, there should be no overhead in the static linking case.


git-svn-id: http://caml.inria.fr/svn/ocaml/branches/ppc64@16228 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
…y maintained when executable has multiple TOCs.

git-svn-id: http://caml.inria.fr/svn/ocaml/branches/ppc64@16230 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
…slightly smaller code.

Plus: force 2^12 alignment of the .opd section so that no page is common to the .opd and the .data sections.  This causes output_value and other polymorphic primitives to misbehave.


git-svn-id: http://caml.inria.fr/svn/ocaml/branches/ppc64@16236 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
  on POWER8.
- PPC64: concatenate jump tables so as to reduce the number of TOC entries
  for jump table labels.
- Use simpler asm directives for filling the TOC.


git-svn-id: http://caml.inria.fr/svn/ocaml/branches/ppc64@16297 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/ppc64@16320 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/ppc64@16322 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
@xavierleroy
Copy link
Copy Markdown
Contributor Author

I forgot to mention performance and optimizations. The proposed code tries (but not very hard) to generate instruction sequences appropriate for instruction fusion on POWER8. Static basic-block instruction scheduling is still based on PPC G3 instruction timings, but this should not make much difference for out-of-order processors like POWER8. If there is a document comparable to "The PowerPC compiler writer's guide" that covers POWER8, I'm interested in reading it.

…ea before calls to C functions.

git-svn-id: http://caml.inria.fr/svn/ocaml/branches/ppc64@16339 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
git-svn-id: http://caml.inria.fr/svn/ocaml/branches/ppc64@16340 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
On a Power7/RHEL6.4 machine, misalignment of the .data section was observed.


git-svn-id: http://caml.inria.fr/svn/ocaml/branches/ppc64@16341 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
@xavierleroy
Copy link
Copy Markdown
Contributor Author

Testing by Luc Maranget on a Power7/RHEL6.4 revealed two bugs in the ppc64 (big-endian) port. Fixed in commits 7dacc03 and 7426611.

ocamlopt -pack can create large .o files that can easily overflow the 16-bit TOC model.


git-svn-id: http://caml.inria.fr/svn/ocaml/branches/ppc64@16342 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
@edelsohn
Copy link
Copy Markdown

There is no Compiler Writer's Guide for POWER8, but the POWER8 processor manual is available.

@bactrian bactrian merged commit e644612 into trunk Aug 25, 2015
@xavierleroy
Copy link
Copy Markdown
Contributor Author

Merged on trunk, SVN revision 16374.

@xavierleroy xavierleroy deleted the ppc64 branch October 27, 2015 13:40
stedolan added a commit to stedolan/ocaml that referenced this pull request Feb 20, 2020
Use C11 atomics to enforce the OCaml memory model.
mshinwell added a commit to mshinwell/ocaml that referenced this pull request Jul 30, 2020
lthls pushed a commit to lthls/ocaml that referenced this pull request Sep 23, 2020
lthls pushed a commit to lthls/ocaml that referenced this pull request Sep 23, 2020
lthls pushed a commit to lthls/ocaml that referenced this pull request Sep 24, 2020
chambart pushed a commit to chambart/ocaml-1 that referenced this pull request Oct 5, 2021
EmileTrotignon pushed a commit to EmileTrotignon/ocaml that referenced this pull request Jan 12, 2024
Co-authored-by: Anil Madhavapeddy <anil@recoil.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants