Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sasho648

macrumors member
Original poster
Feb 19, 2020
82
38
So I made fixes for objconv - currently it compiles my llvm test hello world application (well actually it converts).

It works like this - you compile with whatever llvm compiler you have (I have my own but it'll probably work with clang too) to ppc32 elf.

Then you use this application to convert from elf to ppc32 (the object file).

./objconv -fmacho -nu ./test.c_1.o ./test.c_1_macho.o

Then use gcc to link, unfortunately this is what I'm currently struggling at:

gcc ./test.c_1_macho.o
Undefined symbols:
"printf", referenced from:
_actualfun in test.c_1_macho.o
_test in test.c_1_macho.o
_notajokenow in test.c_1_macho.o
_condtest in test.c_1_macho.o
_main in test.c_1_macho.o
_main in test.c_1_macho.o
_main in test.c_1_macho.o
_main in test.c_1_macho.o
_main in test.c_1_macho.o
_main in test.c_1_macho.o
_main in test.c_1_macho.o
_main in test.c_1_macho.o
_main in test.c_1_macho.o
_main in test.c_1_macho.o
_main in test.c_1_macho.o
_main in test.c_1_macho.o
_main in test.c_1_macho.o
ld: symbol(s) not found
collect2: ld returned 1 exit status


After fixing relocations handling for relocations used in this obj file (it's from my test application for my compiler).

(Initially it wasn't complaining about `printf` at all since it wasn't even adding it to the relocations and the app was just crashing)

Here I have uploaded the src folder with ppc32 binary, the source and my example objs.

Cheers.

EDIT: If anyone is interested actually the relocations here were not working. I managed to get the branch 24bit ones but not yet the 16 half lo/ha.
 

Attachments

  • src.zip
    1.4 MB · Views: 73
Last edited:
  • Like
Reactions: pc297
@barracuda156 I think so yeah.

I think I had a lot of success so far with making it work but as I've mentioned in my edit - currently I need to figure out how to transform 16 bit ha/lo relocations (which are for data - currently the call to printf for example goes through but it fails because the instructions are loading 0 for the string).
 
Do you get symbol errors when running objconv alone? Did you compile it with gcc or llvm-gcc? The reason why I'm asking is that I sometimes had symbol errors with gcc4.2 that disappeared with llvm-gcc. Great idea in any case!
 
@pc297

Lastly I think simply the 16 bit relocation HA LO were offset way off the actual address that needed to be patched - I tried bunch of ways but never figured it out.

Objconv runs fine but when executing - it crashes when you try for example to print a string because the address to it is not patched and it tries to print null.
 
I'll give it a try and look into the source code, I'd be interested to see how it behaves with ppc ELF64
 
I'll give it a try and look into the source code, I'd be interested to see how it behaves with ppc ELF64
For ELF64 - is basically a doppelganger function - you could reference my ELF32 implementation but it wouldn't work out of the box.

(And you need to look also into the Elf32Reloc structure used to parse the image - (Elf64Reloc) - where you have bit-field of 24 that need to be fixed in big endian).
 
  • Like
Reactions: pc297
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.