https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65342

--- Comment #25 from Iain Sandoe <iains at gcc dot gnu.org> ---
I'm going to attach 3 patches, with some comments on how the analysis and
testing arrived there - but some background;

(for the record) Mach-O/Darwin, on PPC generates code in three different
flavours:

1. -mkernel 
 - This is pretty close to ELF '-static' but (a) no TOC, (b) no common (c) use
a branch islands for long calls [with a special "jbsr" instruction and reloc].

 for this flavour we will only see lo_sum contents:
  constant
  symbol
  symbol+constant

2. -mdynamic-no-pic ('static' except for external refs)
 - This is quite similar, with the addition that some data accesses (common,
weak), and some calls are indirected.  When generating for really ancient
linkers, we can also enable symbol stubs for external refs.

 for this flavour lo_sum can contain:
  constant
  symbol
  symbol+constant
  indirection_sym

3. PIC (default)

 - in this case we construct a per function picbase label, and load the picbase
reg with that address -  and compute PC-relative addresses w.r.t this. 
 - undefined, common and weak symbols are indirected (there are some edge
cases, but those don't affect the codegen issues here)

 In principle, the lo_sum could contain

  constant
  symbol
  symbol+constant
  symbol-picbase
  indirection_sym-picbase
  symbol-picbase+constant ** I don't think we're smart enough to generate this,
in reality.

At present, we usually get something like...
  picbase => r31
  addis rx,r31, hi16(sym-picbaselabel)
  ... lo16(sym-picbaselabel)(rx)

=====

For DS mode loads to be valid we need to check:
 - that any offset has the lower two bits clear
 - that the alignment of a referenced symbol is >= 4 [ we can be sure that the
picbase label will be ].

Reply via email to