top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

gcc option for producing stripped binary output

+1 vote
311 views

I am trying to compile a simple c/c++ code using g++. The binary carried more information(symbols). Then I used the option -O3 to get a more optimized code but still there seems to be some information(symbols) not mandatory for the binary execution. I need to use 'strip' command to remove those information.

I felt there must be some gcc/g++ option to get this stripping as part of compilation & linking itself. Can anyone help me with this?

posted Sep 22, 2013 by Meenal Mishra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

simply add -s when linking.

answer Sep 22, 2013 by Sumit Pokharna
Similar Questions
+1 vote

I have an issue in printing a large number in a c program. Please find below the code snippet :

int main()
{
 double temp = 0.0;
 temp = pow(2, 2000);
 printf("The value of temp is %lfn", temp);
 return 0;
}

I compiled and ran as below:

$ gcc test.c -o test
$ ./test
The value of temp is inf

But for the same expression, I am able to get the value from python,

$ python
>>> pow(2,2000)
1148130..........................49029376L
>>>

Can any body help me with that option?

+3 votes

I am following instructions from
https://gcc.gnu.org/wiki/Offloading

I'm using the configure line for Nvidia ptx. The build stops in configuring nvptx-none/libgfortran with error:

checking whether symbol versioning is supported... configure: error: Link tests are not allowed after GCC_NO_EXECUTABLES.

My host OS is CentOS 6.5. I'm using gcc 4.7 (built with system gcc 4.4) to build gcc 5.1

Can someone give me hint to look where the problem could come from ?

0 votes

We are trying to build our code base for CentOS 7 machine with x86_64 architecture on CentOS6 with x86_64.

For that we are trying to build a centos7 Toolchain. All the gcc/ld/ar should be statically linked, so that we are ensuring that it will not uses any native centos6 stuff.

In this process, we are able to generate statically linked GCC/AR/LD. But problem was this GCC not generating a statically linked binaries and fails while checking flags during configure at "checking static
flag -static ". Due to this while running those binaries it refers to native libgcc and fails.

We are using the below command for configure.

../gcc../configure -prefix=/mnt/data0/toolchain-vm-temp2 --build=x86_64-CentOS7-linux-gnu-with sysroot=/mnt/data0/tools/gnutools/toolchain-vm --disable-nls --disable-multilib --enable-languages=c,c++ --disable-sim --enable-symvers=gnu --enable__cxa_atexit --enable-lto --with-gnu-ld --enable-static

Can Anyone provide solution or how to achieve this task.

+2 votes

I would like to build position-independent 4.7 and 4.8 gcc libraries for host: mac target: arm-none-eabi.

Do anyone has instructions for achieving this?

0 votes

I have ported the GCC (v4.5.3) to a new target (32-bit RISC processor). So far everything went fine. I wrote my own little C-Lib with basic input output and tested it worked. Until today I never actually tried optimization passes (maybe that was the mistake that lead to this)
Anyway:
During porting and building Newlib I ran into an error that I tracked down to the following code:

unsigned char hexdig[256];

static void htinit ( unsigned char *h , unsigned char *s , int inc)
{
 int i, j;
 for(i = 0; (j = s[i]) !=0; i++)
 h[j] = i + inc;
}

void
hexdig_init ()
{
 htinit(hexdig, (unsigned char *) "**********", 0x10);
 htinit(hexdig, (unsigned char *) "abcdef", 0x10 + 10);
 htinit(hexdig, (unsigned char *) "ABCDEF", 0x10 + 10);
}

Compiling this code without optimization works like a charm, however compiling it with -O2 leads to the following error:
test1.c: In function 'hexdig_init':
test1.c:11:1: internal compiler error: in gen_lowpart_general, at rtlhooks.c:59

Tried with:
eco32-gcc -O2 -S test1.c

My question in short is:
Could this be a targe- backend-error or just some configuration I have missed while building GCC?
Any pointers into the right direction are welcome.

...