Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

strip breaks COFF/SX files #111

Open
GoogleCodeExporter opened this issue May 5, 2016 · 3 comments
Open

strip breaks COFF/SX files #111

GoogleCodeExporter opened this issue May 5, 2016 · 3 comments

Comments

@GoogleCodeExporter
Copy link

after stripping an executable, superux complains:

bash-2.05b$ ./simple-strip 
bash: ./simple-strip: cannot execute binary file

if stripping an object file containing main() and then linking it into an
executable, it coredumps immediately upon execution with:

bash-2.05b$ ./simple-prestrip 
Illegal instruction (core dumped)

most likely a problem with bfd.

Original issue reported on code.google.com by [email protected] on 17 Feb 2009 at 3:52

@GoogleCodeExporter
Copy link
Author

A part of the problem (the copying of the a.out headers's "magic" and "stack 
size"
attributes) is solved in r190.

However, there is still one issue left: the copying of the section flags is 
still
wrong. Consider the following example:

{{

#include <stdio.h>

void function_in_use() {
    printf("Invoked function in use.\n");
}

void function_not_in_use() {
    printf("ERROR: this function should not be called!\n");
}

int main(int argc, char *argv[]) {

    printf("Testing the \"strip\" tool.\n");

    function_in_use();
    return 0;
}

}}

If we compile it into an "testStripSx" executable and execute the 
"sx8-nec-superux-objdump -h testStripSx" command on it, we get the following 
output:

************ OUTPUT BEGIN ******************
Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         00042c90  0000000400000000  0000000400000000  000001f8  2**3
                  CONTENTS, ALLOC, LOAD, CODE
  1 .data         00008c78  0000000404000000  0000000404000000  00042e88  2**3
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00002b60  0000000404008c80  0000000404008c80  00000000  2**3
                  ALLOC
  3 .comment      000075e0  0000000000000000  0000000000000000  0004bb00  2**3
                  CONTENTS
  4 .whoami       00000f88  00000000000075e0  00000000000075e0  000530e0  2**3
                  CONTENTS, ALLOC, LOAD
************ OUTPUT END ********************

Then, we execute the "sx8-nec-superux-objcump -h testStripSx -o 
testStripSxStripped
-N function_not_in_use" command and the "sx8-nec-superux-objdump -h
testStripSxStripped". We get the following output:

************ OUTPUT BEGIN ******************
Sections:
Idx Name          Size      VMA               LMA               File off  Algn
  0 .text         00042c90  0000000400000000  0000000400000000  000001f8  2**3
                  CONTENTS, ALLOC, LOAD, CODE
  1 .data         00008c78  0000000404000000  0000000404000000  00042e88  2**3
                  CONTENTS, ALLOC, LOAD, DATA
  2 .bss          00002b60  0000000404008c80  0000000404008c80  00000000  2**3
                  ALLOC
  3 .comment      000075e0  0000000000000000  0000000000000000  0004bb00  2**3
                  CONTENTS
  4 .whoami       00000f88  00000000000075e0  00000000000075e0  000530e0  2**3
                  CONTENTS, ALLOC, LOAD, CODE
************ OUTPUT END ********************

We can see that ".whoami" is now regarded as a code section, which is why the 
program
crashes (if we change the flag of the ".whoami" section to its previous value, 
the
"testStripSxStripped" executable works fine).

I did some research and found out that the section flag setting is done in the
following functions in "coffcode.h":
* the "styp_to_sec_flags" function"
* the "coff_write_object_contents" 

These two functions are not SX specific, so it is possible that we have found 
another
bug in binutils...

Original comment by [email protected] on 20 Feb 2009 at 12:57

@GoogleCodeExporter
Copy link
Author

The stripping issue was fixed in r195. 

I still need to test the "coredump when stripping an object file containing 
main()
and then linking it into an executable", though.

Original comment by [email protected] on 13 Mar 2009 at 11:19

@GoogleCodeExporter
Copy link
Author

test it ...

Original comment by [email protected] on 9 Oct 2009 at 9:32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant