An interesting Dongdong Linux C prints its own program

Source: Internet
Author: User

 

Test. c

# include < stdio. h>
# include < stdlib. h>

extern char * _binary_test_c_start;
int main( )
{
  printf ( "%s" , ( char * ) & _binary_test_c_start) ;

  printf("hahah/n");
}

 

Makefile

SRC = test . c
TAR = test
ALL: test . c
        objcopy - I binary - O elf32- i386 - B i386 test . c test . bin
        gcc - o test test . c test . bin

 

Objcopy can easily make text files into objects that can be connected by connectors, and then link them into executable programs.

 

[Root @ kenthy c_par] #./test
# Include <stdio. h>
# Include <stdlib. h>

Extern char * _ binary_test_c_start;

Int main ()
{
Printf ("% s", (char *) & _ binary_test_c_start );
Printf ("hahah/N ");
Return 0;
}
Hahah

A little boring !!! I have never used objcopy. ^_^

 

Original article: http://blog.chinaunix.net/u/1574/showart_2032979.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.