avrdudes / avr-libc

The AVR-LibC package provides a subset of the standard C library for AVR 8-bit RISC microcontrollers.
https://avrdudes.github.io/avr-libc/
Other
261 stars 56 forks source link

ld: undefined reference to `E2END' #973

Closed sprintersb closed 3 months ago

sprintersb commented 3 months ago

This error can occur for devices without EEPROM memory, because E2END is added to the .note.gnu.avr.deviceinfo section, but E2END is never defined in avr/io.h.

This was added 2014-11-21 with 4a58441b2b5b6a347d324798c047bb8b8f439351

sprintersb commented 3 months ago

Test case: $ avr-gcc main.c -mmcu=attiny102

int main (void)
{
    return 0;
}
dl8dtl commented 3 months ago

Besides the venerable AT90S1200 (which was not targetted to C), there were probably no devices without EEPROM back 10 years ago. Does that look like the correct fix?

diff --git a/crt1/gcrt1.S b/crt1/gcrt1.S
index 699aa482..a93c0f1b 100644
--- a/crt1/gcrt1.S
+++ b/crt1/gcrt1.S
@@ -365,8 +365,10 @@ __do_copy_data:
     .long EEPROM_SIZE
 #elif E2END > 0
     .long E2END + 1
-#else
+#elif defined(E2END)
     .long E2END
+#else
+    .long 0
 #endif
     /* String offsets table.
     Index 0 - Size of offset table in bytes
dl8dtl commented 3 months ago

Seems to fix your testcase, at least. Shall I commit it?

sprintersb commented 3 months ago

I think we can just

diff --git a/crt1/gcrt1.S b/crt1/gcrt1.S
index 699aa482..0e854fa4 100644
--- a/crt1/gcrt1.S
+++ b/crt1/gcrt1.S
@@ -366,7 +366,7 @@
 #elif E2END > 0
     .long E2END + 1
 #else
-    .long E2END
+    .long 0
 #endif
     /* String offsets table.
     Index 0 - Size of offset table in bytes

Negative E2END wouldn't make any sense.

dl8dtl commented 3 months ago

There are other cases (flash and RAM) that look similar. Maybe we can skip that "+1" part just everywhere then?

dl8dtl commented 3 months ago

OK, fixed. While at it, I changed the code for FLASHEND in a similar way.

dl8dtl commented 3 months ago

done

sprintersb commented 3 months ago

Thanks.