Thread: Compiling to pure binary with GCC

  1. #1
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163

    Compiling to pure binary with GCC

    How can I compile independant C code to pure x86 16 and 32 bit binaries? Is there a way to do it with mingw, or do I have to compile a special version of GCC?
    Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
    What profit hath a man of all his labour which he taketh under the sun?
    All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
    For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.

  2. #2
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Pure binaries? Meaning what? An executable?

  3. #3
    Registered User
    Join Date
    Aug 2008
    Location
    Belgrade, Serbia
    Posts
    163
    Meaning no executable format, no information headers, no sections; just pure binary, instructions.
    Vanity of vanities, saith the Preacher, vanity of vanities; all is vanity.
    What profit hath a man of all his labour which he taketh under the sun?
    All the rivers run into the sea; yet the sea is not full; unto the place from whence the rivers come, thither they return again.
    For in much wisdom is much grief: and he that increaseth knowledge increaseth sorrow.

  4. #4
    pwns nooblars
    Join Date
    Oct 2005
    Location
    Portland, Or
    Posts
    1,094
    Likely possible, would have to read though the documentation for your compiler. There is a lot of information for GCC and most of it applies to MinGW also.

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I think the switch you're looking for is -ffreestanding.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    The various parts/sections/layout of executable files are documented. If you have a need to extract particular sections, easier to write a separate program to extract them than to modify a compiler.

    I must admit I fail to see value in doing this. A set of instructions without the data they act on would be rather useless. You would have some trees, but not even be aware of the forest.

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Code:
    objcopy -O binary input.elf output.bin
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  8. #8
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by grumpy View Post
    I must admit I fail to see value in doing this. A set of instructions without the data they act on would be rather useless. You would have some trees, but not even be aware of the forest.
    A dump of all the raw section contents will include the data as well as the code. As long as everything has already been relocated, the code will be loaded at the appropriate address (the linker can control that) and/or the code is position independent, it will work fine.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GCC: Compiling with both static and shared libraries
    By eatwithaspork in forum C Programming
    Replies: 4
    Last Post: 06-23-2008, 01:48 PM
  2. Question about linux compiling with GCC
    By elsheepo in forum C++ Programming
    Replies: 23
    Last Post: 03-07-2008, 11:36 PM
  3. compiling with gcc in linux error
    By k4z1nh0 in forum C Programming
    Replies: 2
    Last Post: 03-03-2005, 09:52 AM
  4. Compiling in Linux - GCC
    By gqchynaboy in forum C Programming
    Replies: 15
    Last Post: 03-02-2005, 12:15 PM
  5. Compiling with gcc
    By tiberiumwaster in forum Linux Programming
    Replies: 2
    Last Post: 03-11-2002, 04:27 AM