Find the answer to your Linux question:
Results 1 to 6 of 6
I have a specific problem and a general problem, and I'm hoping someone here can help with at least one of them. My overall task is to convert some .obj ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2010
    Posts
    4

    Question Problem with gnu objcopy, trying to translate from MSVC to gcc


    I have a specific problem and a general problem, and I'm hoping someone here can help with at least one of them.

    My overall task is to convert some .obj files generated under MSVC/Windows (from masm, specifically), to a format that can be linked in under gcc. Objcopy looks like the right tool for that, but I'm having issues.

    I'm running objcopy in a command prompt under WinXP at the moment, though I could try it under Linux if that looked useful.

    Anyway, if I look at a .obj file from MSVC using objdump, I get interesting information. My plan was to compare this to what objdump shows about a gcc ".o" file and then work out what needs to be converted with objcopy.

    However, when I (under Windows, still) run objcopy on the .o file, I get

    >objdump -t linux.o
    objdump: linux.o: Permission denied

    Now, the permissions on this file are identical to those in the .obj file, which worked fine. If I run objdump on a random file, it tells me it can't recognize the file format, so that's not the problem either. I get the same result running objcopy and "size" on this file, though the tool "strings" ran fine on it. So question #2 is what the heck is going on there?

    I'll note that this is an old version of the gnu binutils, if that's relevent:

    GNU objdump 2.8-B19
    Copyright 1997 Free Software Foundation, Inc.

    And here's what this install of objcopy knows about:

    objcopy: supported targets: pe-i386 pei-i386 srec symbolsrec tekhex binary ihex

    I'm new at this, and I'm not even sure what the "correct" formats here are, though this is entirely for use on modern Intel chips.

    Thank you all for any help you can provide. I've had virtually no luck in finding out more information about these tools beyond the man pages. (and if anyone knows how to solve the overall task easily, that would be even better!)

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,577
    Windows .obj files are not in the same format as Linux .o files, so don't expect Windows tools to be able to get anything "interesting" out of them. MS development tools are notoriously MS-specific. Also, trying to convert a .obj file to a .o file is likely to be an exercise in futility as it is likely they are referencing a lot of MS-specific functions. So, the first question is, do you have the original source code? You say these are generated from .asm files. You will have some work to do, but you might be able to convert them to be compatible with the Linux assembler.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Just Joined!
    Join Date
    Oct 2010
    Posts
    4
    Thanks for the quick response.

    I do have the source code, but I effectively cannot modify it to get it to assemble under gnu by itself. The .objs have functions that make no function calls of their own, nor do they reference any global variables, so I really only have to get "my" functions callable from gcc without worrying about anything else. From that perspective, it's a best-case scenario. I can also live without debugging information or anything else like that.

    The tool in question is gnu objcopy, which I would assume should be able to figure out a linux-gcc-generated .o file regardless of what platform I run objcopy on... ? To my surprise, objcopy and objdump have no trouble reading and understanding the MSVC-generated .obj file.

  4. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,577
    Ok. Let me think about this awhile. The only thing I can think of offhand is that objcopy may not be generating a valid .o file. I haven't used it personally so I'll have to look into it. FWIW, have you tried a newer version of binutils. You mention that yours is a bit dated.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  5. #5
    Just Joined!
    Join Date
    Oct 2010
    Posts
    4
    Quote Originally Posted by Rubberman View Post
    Ok. Let me think about this awhile. The only thing I can think of offhand is that objcopy may not be generating a valid .o file. I haven't used it personally so I'll have to look into it. FWIW, have you tried a newer version of binutils. You mention that yours is a bit dated.
    Thanks again..

    To be clear, the .o file was generated by gcc running under Linux, then moved across to my windows box to try and get this other stuff working. I haven't actually used objcopy yet... just trying to "objdump" the information in the gcc output so far.

    Going to try to find a newer version of the binutils, but I was unable to install the latest one here on my PC because of installer problems etc.. wasn't fun.

  6. #6
    Just Joined!
    Join Date
    Oct 2010
    Posts
    4
    Got much more recent version (via cygwin) and it seems to be working now. Thanks for the help and sorry for the trouble.. Hopefully I can actually solve the problem I'm trying to solve as well

    (still wondering where such a weird "permission error" would come from though!)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •