Contest: make 32-bit PEs & ELFs easy bootable & relocateable
Posted: Thu Apr 01, 2010 10:37 pm
GOAL
The goal of this contest is to be able to compile boot executable and modules in a "standard" manner and then load and relocate them at boot time with minimum effort and maximum ease.
Essentially, I am looking for a utility that reads PEs and ELFs executables and replaces headers with an init code that will do base relocations to a reasonable target address specified at runtime. Initially you can pick as input either 32-bit PE or ELF executable and make resulting boot binary either multiboot compliant or be loadable directly from a boot sector (if you want to switch to 32-bit protected mode yourself).
TEST PLAN
One of the test cases will be a little C program that writes something directly to the video memory at address 0xB8000 and then halts itself with while(1). It will be compiled using a "standard" compiler with options to generate either PE or ELF 32-bit executable with base relocations information and do not include any c0sx init code. Test programs will use at least one of each: global string constant, global variable, and a function address.
Test cases will include C/C++ command line executables generated by the following compilers: gcc, tcc, msvs/cl. I intend to use default compile and link options, but if anyone runs into any issues speak up and we could tweak them. Sample test code and compile instructions will be posted in this thread later.
RULES
This is preliminary rules for the Part II: dates are TBD
Questions and suggestions are welcome. If anyone wants to co-sponsor this contest and bump-up prizes it will be greatly appreciated!!!
The goal of this contest is to be able to compile boot executable and modules in a "standard" manner and then load and relocate them at boot time with minimum effort and maximum ease.
Essentially, I am looking for a utility that reads PEs and ELFs executables and replaces headers with an init code that will do base relocations to a reasonable target address specified at runtime. Initially you can pick as input either 32-bit PE or ELF executable and make resulting boot binary either multiboot compliant or be loadable directly from a boot sector (if you want to switch to 32-bit protected mode yourself).
TEST PLAN
One of the test cases will be a little C program that writes something directly to the video memory at address 0xB8000 and then halts itself with while(1). It will be compiled using a "standard" compiler with options to generate either PE or ELF 32-bit executable with base relocations information and do not include any c0sx init code. Test programs will use at least one of each: global string constant, global variable, and a function address.
- 1. Compile test.c into test.exe:
- let say, it will have default base (4Mb),
- code section and entry point at (4Mb+4k),
- data section at (4Mb+8k), and bss section (4Mb+12k)
- 2. Your utility should take text.exe as input and produce test.bin
- 3. Somehow set new target address by changing 4 bytes inside test.bin (specific offset?) to (2Mb)
- 4. Use modified test.bin to create floppy image with GRUB that will load test.bin to some address (64k)
- 5. Test it under QEMU or VMware:
- your init code should copy and rebase
- original code section to (2Mb+4k),
- data section to (2Mb+8k), clear bss, and
- jump to the proper entry point at (2Mb+4k).
Test cases will include C/C++ command line executables generated by the following compilers: gcc, tcc, msvs/cl. I intend to use default compile and link options, but if anyone runs into any issues speak up and we could tweak them. Sample test code and compile instructions will be posted in this thread later.
RULES
- Your source code must be ISC licensed similarly to other contests on this forum
- All entries must be posted to this thread with source code and compile instructions attached (no links)
- You can use GRUB only to load boot binary, set up initial stack, and get control in 32-bit protected mode
- You cannot utilize any advanced GRUB functionality or additional modules (compression, ELF handling, etc...)
- Accepted are C, C++, and x86 assembler sources compilable with tcc, gcc, gasm, fasm, nasm, or msvs/cl/masm
- Prizes will be awarded via PayPal in USD within two weeks of contest closing date (i.e. entry submission deadline)
- Entries are accepted starting May 1, 2010 00:00:01 UTC
- For entry to qualify resulting boot binaries must be less or equal to the original executable size.
- There are three separate $25 prizes:
- First entry that successfully boots PE executable (generated by one of compilers) gets $25
- First entry that successfully boots ELF executable (generated by one of compilers) gets $25
- First entry that successfully handles both PE and ELF executables and all compilers (tcc,gcc,msvc) gets remaining $25
- Deadline for the first part of the contest is May 31, 2010 23:59:59 UTC
This is preliminary rules for the Part II: dates are TBD
- Your utility needs to build upon the best solution from the Part I and create a compressed boot binaries for each test case
- There will be three test executables: ~12k (public), ~64k (hidden), ~256k (public) ;; (size, gzipped size, and md5s will be public)
- Each executable will be compressible by ~2 times using gzip and will contain similar proportion of code, globals, and text messages.
- Init code should decompress original code, perform base relocations and jump to the executable entry address
- In order to qualify first entry must produce binaries at least 1024 bytes less than ones produced by the uncompressed winning entry from the Part I
- Each subsequent entry must improve total compressed size by at least 1024 bytes and no binary should be larger than best result of the previously qualified entry
- Example:
- First entry: 9k, 51k, 180k (total=240k) -> quilifies.
- Second entry: 11k, 49k, 160k (total=220k) -> nop
- Third entry: 9k, 49k, 142k (total=200k) -> quilifies.
- Fourth entry: 8k, 42k, 140k (total=190k) -> quilifies.
- Last Qualified entry on the contest closing date wins $60 prize!
- There will be a extra $40 prize if winning entry uses decompressor code attached below.
Questions and suggestions are welcome. If anyone wants to co-sponsor this contest and bump-up prizes it will be greatly appreciated!!!