Files
test/linux/elf_sections.cpp
2015-03-03 11:49:35 +04:00

54 lines
938 B
C++

/*
VIM: let g:lcppflags="-std=c++11 -O2 -pthread"
VIM: let g:wcppflags="/O2 /EHsc /DWIN32"
*/
#include <iostream>
#include <exception>
char var_bss[20];
int ivar_bss;
char var_data[] = "string in data";
int ivar_data = 10;
const char var_rodata[] = "string in rodata";
const int ivar_rodata = 10;
__attribute__((section(".custom")))
char var_custom[] = "string in custom section";
__attribute__((section(".custom")))
int ivar_custom = 10;
void test()
{
const char * var_ptr = "string in rodata 2";
std::cout
<< var_bss
<< var_data
<< var_rodata
<< var_ptr
<< &ivar_custom
<< &ivar_rodata ;
}
int main ( void )
{try{
system("objdump -t elf_sections.exe | grep var");
return 0;
}
catch ( const std::exception& e )
{
std::cerr << std::endl
<< "std::exception(\"" << e.what() << "\")." << std::endl;
return 2;
}
catch ( ... )
{
std::cerr << std::endl
<< "unknown exception." << std::endl;
return 1;
}}