0

I'm using a cross compiler on a 64-bit Intel-based Linux system to build some of our software so it can run on a 32-bit PowerPC chip. The cross compiler was produced by Crosstools.

When I run "readelf -a" against the shared object files (.so files) produced by the cross compiler, part of the output shows this:

Program Headers:
  Type           Offset   VirtAddr   PhysAddr   FileSiz MemSiz  Flg Align
  LOAD           0x000000 0x00000000 0x00000000 0x9a87c 0x9a87c R E 0x10000
  LOAD           0x09a87c 0x000aa87c 0x000aa87c 0x01344 0x03230 RWE 0x10000
  DYNAMIC        0x09ba84 0x000aba84 0x000aba84 0x000d0 0x000d0 RW  0x4
  GNU_EH_FRAME   0x09a7bc 0x0009a7bc 0x0009a7bc 0x0002c 0x0002c R   0x4
  GNU_STACK      0x000000 0x00000000 0x00000000 0x00000 0x00000 RW  0x4

The problem is that header marked RWE. A potential customer evaluating our software has issues with that and wants it to be just RW.

A second cross compiler, produced by the same version of Crosstools and targeting the same version of gcc, produces code for 64-bit PowerPC chips. The shared object files produced by this cross compiler do not produce any RWE headers (the second LOAD header is marked just RW).

The qualifiers for gcc for both the compiles and the links are the same in both cases.

I'm kind of new to the world of cross compilers and ELF headers. Is there a way to get the 32-bit cross compiler to create shared object files without a header marked RWE?

Failing that, is there a way to (safely) patch an already created .so file to change a header marked RWE so it's marked RW?

Douglas Coup
  • 57
  • 1
  • 2

1 Answers1

1

Can you check the section-to-program-header mapping (eu-readelf -l)? I'm pretty sure this happens because your target configuration doesn't enable by default the secure GOT feature that was implemented for GNU/Linux some time ago:

See --bss-plt and --secure-plt in ld and PowerPC 32-bit ELF Support for flags to control this behavior. If you use a custom program loader, you may have to tweak it for secure PLT support. The glibc dynamic linker supports it.

(And your customer is very astute, congratulations.)

EDIT If --secure-plt does not work, your PowerPC sub-target is either incompatible with it, you built the toolchain incorrectly, or there's a linker script which overrides its effect.

Florian Weimer
  • 32,022
  • 3
  • 48
  • 92
  • Our build system doesn't have the eu-readelf command. I added --secure-plt to the link options and -msecure-plt to the compile options. The options didn't produce any command errors, but the .so files created still have the RWE header. – Douglas Coup Feb 22 '18 at 15:02