From 27b81b461fbc754779b2c941b9e1b9e49d54211b Mon Sep 17 00:00:00 2001 From: Simon Marlow Date: Thu, 10 May 2007 09:31:35 +0000 Subject: [PATCH] improve comments about x86-64 relative-offset hackery --- compiler/nativeGen/PprMach.hs | 3 ++- driver/mangler/ghc-asm.lprl | 2 ++ includes/InfoTables.h | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/compiler/nativeGen/PprMach.hs b/compiler/nativeGen/PprMach.hs index 3e2161e..446495a 100644 --- a/compiler/nativeGen/PprMach.hs +++ b/compiler/nativeGen/PprMach.hs @@ -760,7 +760,8 @@ pprDataItem lit -- Fortunately we're assuming the small memory model, in which -- all such offsets will fit into 32 bits, so we have to stick -- to 32-bit offset fields and modify the RTS appropriately - -- (see InfoTables.h). + -- + -- See Note [x86-64-relative] in includes/InfoTables.h -- ppr_item I64 x | isRelativeReloc x = diff --git a/driver/mangler/ghc-asm.lprl b/driver/mangler/ghc-asm.lprl index 0bda1bb..91d20d6 100644 --- a/driver/mangler/ghc-asm.lprl +++ b/driver/mangler/ghc-asm.lprl @@ -236,6 +236,8 @@ sub init_TARGET_STUFF { # where x is in the text section and y in the rodata section. # It works if y is in the text section, though. This is probably # going to cause difficulties for PIC, I imagine. + # + # See Note [x86-64-relative] in includes/InfoTables.h $T_HDR_relrodata= "\.text\n\t\.align 8\n"; $T_HDR_closure = "\.data\n\t\.align 8\n"; diff --git a/includes/InfoTables.h b/includes/InfoTables.h index 67bd97b..3e556ef 100644 --- a/includes/InfoTables.h +++ b/includes/InfoTables.h @@ -216,11 +216,21 @@ typedef struct StgLargeSRT_ { relative to the info pointer, so that we can generate position-independent code. + Note [x86-64-relative] There is a complication on the x86_64 platform, where pointeres are 64 bits, but the tools don't support 64-bit relative relocations. However, the default memory model (small) ensures that all symbols have values in the lower 2Gb of the address space, so offsets all fit in 32 bits. Hence we can use 32-bit offset fields. + + When going via-C, the mangler arranges that we only generate + relative relocations between symbols in the same segment (the text + segment). The NCG, however, puts things in the right sections and + uses 32-bit relative offsets instead. + + Somewhere between binutils-2.16.1 and binutils-2.16.91.0.6, + support for 64-bit PC-relative relocations was added, so maybe this + hackery can go away sometime. ------------------------------------------------------------------------- */ #if x86_64_TARGET_ARCH -- 1.7.10.4