What is __aeabi_unwind_cpp_pr1 'and how can I avoid it?

I have a group of assemblies, C and C ++ files. gcc tries to link them, but they are for an embedded project.

I don't use any external libraries, all the code I use was written by me. An error occured because I have a function named int kernel_main(void)

in main.c

, which is trying to call set_LED(int value)

, defined in mailbox.cpp

, which includes the header mailbox.h

(I included the header in the main.c file).

The exact error:

undefined reference to `__aeabi_unwind_cpp_pr1'

      

How I do my project: -compile all source files (.s, .c, .cpp) into unreferenced object files (.o) (-c) and then link them all together using a custom linker script.

Edit: I'm going to add some information to make things clearer.

First you need to change all files so that they are all C files (without cpp extensions):

undefined reference to `set_LED'

      

It is unlikely that the problem itself is the name governing it, probably has nothing to do with the CPP and C differences.

The problem will most likely be a linker problem

This is the build process:

Compile c files, example:

arm-none-eabi-g++ -O0 -march=armv8-a source/MainFiles/mailbox.cpp -nostartfiles -c -o objects/MainFiles/mailbox.o

      

(Compiling the C ++ file will be identical, except for using g ++ instead of gcc)

Link everything:

arm-none-eabi-ld object1 object2... -o build/kernel.elf -T ./source/kernel.ld -I include_directory_1 -I include_directory_2 -L include_directory_1 -L indlude_directory_2

      

Include directories - all directories under the current one

Edit: The error returned. Ignore the title part of this question. The error I need to fix:

./objects/Hardware/mailbox.o:(.ARM.exidx+0x18): undefined reference to `__aeabi_unwind_cpp_pr1'

      

So far, all I know is that it has something to do with stack unwinding and exceptions. The function seems to be defined in libgcc. However I used -nostdlib

, I omitted it and in both cases the error persists. I tried changing the file extensions to .c when possible and to .cpp when possible, alas, there is always an error.

It was only fixed as long as I had exactly 1 cpp file and the rest of my files were C files (this is no longer the case, I tried). What caused the error again was that I was refactoring the code and I wanted to move a few functions to new files.

In other words, without deleting one file, declaring a function named wait(uint32_t time)

in mailbox.cpp works, declaring it in a file named time.c (or cpp) with its appropriate header declaration and including the header in the mailbox .cpp breaks everything. Note. I don't delete files when moving a function. I just remove the function declaration inside each file.

Add a stub like this:

void __aeabi_unwind_cpp_pr1()
{

}

      

Fixes the problem and the code works. But I don't like it. I don't want the useless stub to be called mysteriously in my code. I don't need or need this feature in my current implementation, how can I tell the compiler or linker to omit anything they do that requires this feature?

+3


source to share


4 answers


The solution is very simple. As it turns out, exceptions are enabled by default (this is what generates the code that calls __eabi_unwind_cpp_pr1

). To disable them, you need: -fno-exceptions

as an argument to the gcc / g ++ compiler and the issue is resolved.



+1


source


I've seen this when mixing C and C ++. Due to the name change, symbols will have different names within themselves depending on the type of the source file.

If the source for 'set_LED' is a c file, use the following in the prototype header and see if it helps.



#ifdef __cplusplus
extern "C" {
#endif

// function prototypes here

#ifdef __cplusplus
}
#endif

      

+1


source


You have a link to this function related to the C ++ GCC runtime. This is part of the exception handling. Whatever you do sounds a little crazy, but you can do it anyway if you really know what you are doing. You have to link to the C ++ runtime libraries. It. Link to "libstd ++".

Oh set_LED

I also believe this is just a C ++ issue, just like Justin J mentioned in another answer.

0


source


Also add the "-shared" prefix without quotes to -fno-exceptions. I am using ARM version of GCC

-2


source







All Articles