Debugging globally defined constructors.

Thank you westfw.

I added the assembler source of .section .init5 in Arduino IDE and confirmed that it was added by disassembler. My problem is a solution.
I am happy.

I want to check the linker script. The following is the linker execution log. The linker script specification cannot be found.
Linking everything together...
"D:\C_EXT_WIN10\arduino-1.8.13-windows\arduino-1.8.13\hardware\tools\avr/bin/avr-gcc"
-w
-Os
-g
-flto
-fuse-linker-plugin
-Wl,--gc-sections
-mmcu=atmega32u4
-o "D:\C_EXT_~1\User\yoshi\AppData\Local\Temp\arduino_build_473170/constructorCall.ino.elf"
"D:\C_EXT_~1\User\yoshi\AppData\Local\Temp\arduino_build_473170\sketch\constructorCall.ino.cpp.o"
"D:\C_EXT_~1\User\yoshi\AppData\Local\Temp\arduino_build_473170/core\core.a"
"-LD:\C_EXT_~1\User\yoshi\AppData\Local\Temp\arduino_build_473170"
-lm

Default linker scripts are in:
.../arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7/avr/lib/ldscripts
It looks like 32u4 builds use avr5.xn: /* Script for -n: mix text and data on same page */

"avr5" specifies the "sub-architcture" within AVR. More than 8k of program memory, less than 128k, etc. A Nano Every (w atmega4809) would use xmega3.xn, and a Mega (atmeg2560) would use avr6.xn

You can see what it's doing by adding a "-Wl,--verbose" to the link command.

I don't understand the function call between assembler and C language. Where is the error below?

Call C init5x () from the assembler.
Call the assembler zxy: from C ++.

Linking everything together...
"D:\C_EXT_WIN10\arduino-1.8.13-windows\arduino-1.8.13\hardware\tools\avr/bin/avr-gcc" -w -Os -g -flto -fuse-linker-plugin -Wl,--gc-sections -mmcu=atmega328p -o "D:\C_EXT_~1\User\yoshi\AppData\Local\Temp\arduino_build_473170/constructorCall.ino.elf" "D:\C_EXT_~1\User\yoshi\AppData\Local\Temp\arduino_build_473170\sketch\test.S.o" "D:\C_EXT_~1\User\yoshi\AppData\Local\Temp\arduino_build_473170\sketch\constructorCall.ino.cpp.o" "D:\C_EXT_~1\User\yoshi\AppData\Local\Temp\arduino_build_473170/..\arduino_cache_406767\core\core_arduino_avr_uno_430a8a8d300838305782cf3f2a6a2c93.a" "-LD:\C_EXT_~1\User\yoshi\AppData\Local\Temp\arduino_build_473170" -lm
D:\C_EXT_~1\User\yoshi\AppData\Local\Temp\cc30vfba.ltrans0.ltrans.o: In function loop': D:\C_EXT_WIN10\User\yoshi\Documents\Arduino\SPI\constructorCall/constructorCall.ino:29: undefined reference to xyz()'
D:\C_EXT_~1\User\yoshi\AppData\Local\Temp\arduino_build_473170\sketch\test.S.o:D:\C_EXT_~1\User\yoshi\AppData\Local\Temp\arduino_build_473170\sketch/test.S:6: undefined reference to `init5x'
collect2.exe: error: ld returned 1 exit status
exit status 1
ボードArduino Unoに対するコンパイル時にエラーが発生しました。

/*

  • Arduino アセンブラソース
    */
    .section .init5,"ax",@progbits
    inc r16
    CALL init5x

/*
void zxy();
*/
.section .text,"ax",@progbits
.global xyz
.func xyz
ret
.endfunc

#define con Serial
//#define con Serial1

class _TEST {
public:
_TEST(int argId) {
con.begin(57600);
}
};

bool ini5_info = false;

void init5x()
{
ini5_info = true;
}

_TEST test(1);

void setup() {
// con.begin(57600);
// while(!con);
con.println("test");
}

void xyz();

void loop() {
xyz();
}

Thank you westfw.

Addition of "-Wlverbose", comfortable. I think many questions will be answered.

:slight_smile: :slight_smile: :slight_smile:

Thank you for everything.
My first goal can be achieved with the following modifications.

  1. Call ini () with init5 and then
  2. Execute serial.bign
  3. Delete init () in main ().
    It may be better to call initVariant () in main () at the end of init ().
    I think it is better to enable interrupts in init () after hardware initialization.

My second question is why the init() call comes after the execution of the constructor. I think init() is the HW initialization process. Executing the constructor is software initialization. I think that it should be done as soon as possible after initializing the variables with initial values of the hardware, initializing the bss, and setting the stack. I think it's correct to do it before the variables are initialized by the constructor.
I hope this fix will be realized in the Arduino release version.

:slight_smile: :slight_smile: :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.