简体   繁体   中英

BFD_RELOC_64: Compiling assembler directives on a 32 bit linux with C++

I'm trying to compile the code below on a 32 bit Linux with GCC 4.4.1.

#ifndef WIN32
    #define DEBUG_STOP_POINT()                     \
        asm ( " 0 : int3 ; "                       \
              " .pushsection embed-breakpoints ; " \
              " .quad 0b ; "                       \
              " .popsection ; " )

        #if defined ( _DEBUG ) && defined ( _ASPECT_DEBUG )
            #define THROW_BREAKPOINT()                     \
                asm ( " 0 : int3 ; "                       \
                      " .pushsection embed-breakpoints ; " \
                      " .quad 0b ; "                       \
                      " .popsection ; " )
        #else
            #define THROW_BREAKPOINT()                         \
                asm ( " 0 : .pushsection embed-breakpoints ; " \
                      " .quad 0b ; "                           \
                      " .popsection ; " )
        #endif
#else
    #define DEBUG_STOP_POINT()
    #define THROW_BREAKPOINT()
#endif

It was taken from a 64 bit project running on the 64 bit version of the same Linux where it compiles without problems with the same GCC 4.4.1. Every place where THROW_BREAKPOINT() (the DEBUG_STOP_POINT() is never used) is used issues the compile error: "cannot represent relocation type BFD_RELOC_64."

And now the questions:

  1. What does this code ?
  2. These asm directives are 64 bit only ? Is so, could you, please, rewrite it in order to do the same thing on my 32 bit system (32 bit Intel Celeron M) ?
  3. May I suspect a compiler installation issue (the compiler and the required dependencies were installed from rpms on top of the existing and newer gcc using rpm -ivh --force options)? In this case, could you give me am example of code using asm directives which should compile on my 32 bit box ?
  4. What else may I try to fix the compile error (well, something different of using empty definitions as it is for the WIN32 case) ?

1) Obviously, it's hard to tell exactly WHY the code is there without some context, but this is what it "does":

    asm ( " 0 : int3 ; "                       \     # INT3 = Breakpoint instruction
          " .pushsection embed-breakpoints ; " \
          " .quad 0b ; "                       \     # Trap detection address
          " .popsection ; " )

The pushsection and popsection change what section the data is in (by saving on a stack, and then restoring back to whatever it was originally (typically .text , but obviously some other inline assembler or #pragma may have changed that before this particular point.

For 32-bit code, you'd probably want a .long instead of .quad for the trap detection address - this would make this reference a 32-bit value rather than a 64-bit value - the linker won't like 64-bit values... I don't know exactly what the purpose of the embed-breakpoints section is - it's presumably scanned to understand where the actual breakpoint happened, or some such. It stores the address of 0: , in other words the address of the int3 instruction.

Obviously, the #if _DEBUG ... bit is just a way to select a breakpoint for debug or no breakpoint variation of the code for non-debug mode.

2) You would really have to ask whoever wrote the code - didn't see a need for 32 bits, I expect.

3) Uh? We can't tell what you installed from what you have asked, and it's impossible to tell if it's installed "correctly" or not. As for examples, I'm pretty sure there are tutorials, but changing .quad to .long should fix the immediate error in the title of your post - of course, there are most likely some other code that actually uses this content that may also need to be changed.

4) Not sure what you are asking for here?

Note that I'm trying to read your mind in my answer, so apologies if my "force" is not strong today, and I have answered something else than what you asked for. It would REALLY help (for future reference) if you posted:

  1. Some code that uses these macros.
  2. What the "project" is that you took the source from, assuming it's an open source project. Then it would be possible to download the sources and scan through and understand what it does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM