[cfe-dev] linux/i386 and mregparm

Anton Korobeynikov anton at korobeynikov.info
Tue Mar 1 13:06:18 PST 2011


> the same is true for the positive 32 (well, 31) bit address space where
> the main executable resides yet clang doesn't forbid *all* positive offsets
> on grounds that they may wrap and address the negative address space.
Not at all! Everything is perfectly as allowed by the ABI (this the
code just few
lines upper the code you commented out):

  // For small code model we assume that latest object is 16MB before end of 31
  // bits boundary. We may also accept pretty large negative constants knowing
  // that all objects are in the positive half of address space.
  if (M == CodeModel::Small && Offset < 16*1024*1024)
    return true;

> fff8305dd7e:       48 8b 35 eb 05 e5 ff    mov    -0x1afa15(%rip),%rsi        # ffffffff82eae370 <key_type_dns_resolver>
This is completely different thing. The hook is used to fill the
signed offset field of the global symbol.
We *have* to make sure that the address is still valid after actual linking.

> i said, i needed a quick hack to get rip relative addressing to work so i
> just went with disabling this range check. if there's a better, i'm all
> ears ;).
Leave it as-is, the current code does correct things per x86-64 ABI.
Check test/CodeGen/X86/codemodel.ll which tests various different
aspects of small vs kernel code models.
You can translate the IR to C code for better readability, but
basically the code just does something like this:

int *foo;

int bar(void) {
   return foo[offset];
}

for different values of the offset (small positive, big positive, smal
negative, big negative).

-- 
With best regards, Anton Korobeynikov
Faculty of Mathematics and Mechanics, Saint Petersburg State University




More information about the cfe-dev mailing list