Christian Weisgerber <na...@mips.inka.de> writes:
Hello,

I may have encountered the same bug when I tried to build programs
generated with devel/arduino. cc1 aborts with a coredump during the
compilation.

I think I have found the culprits: both ISR() and SIGNAL() macros from
avr/interrupt.h use the __attribute__((signal)).
(extract from avr/interrupt.h at the end of my mail)

I don't know how much retguard nor __attribute__((signal)) work, but my
guess is that they are stepping on each others foot.

Once I removed the signal attribute form the ISR and SIGNAL macros, I
was also able to compile the programs generated with devel/arduino
without coredump but it doesn't work on the arduino, I guess the
attribute wasn't there for nothing....

When I looked at devel/simulavr source code, the only occurence of the
ISR() macro was in the tests. I was able to build devel/simulavr by
disabling the tests (./configure --disable-tests). However, I wasn't
able to test it because the documentation is for a newer version
(1.0.0), so I end up upgrading devel/simulavr which does work (patch
attached).

Best,

avr/interrupt.h:
/** \def ISR(vector [, attributes])
    \ingroup avr_interrupts

    Introduces an interrupt handler function (interrupt service
    routine) that runs with global interrupts initially disabled
    by default with no attributes specified.

    The attributes are optional and alter the behaviour and resultant
    generated code of the interrupt routine. Multiple attributes may
    be used for a single function, with a space seperating each
    attribute.

    Valid attributes are ISR_BLOCK, ISR_NOBLOCK, ISR_NAKED and
    ISR_ALIASOF(vect).

    \c vector must be one of the interrupt vector names that are
    valid for the particular MCU type.
*/
#  define ISR(vector, [attributes])
#else  /* real code */

#if (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) || (__GNUC__ > 4)
#  define __INTR_ATTRS used, externally_visible
#else /* GCC < 4.1 */
#  define __INTR_ATTRS used
#endif

#ifdef __cplusplus
#  define ISR(vector, ...)            \
    extern "C" void vector (void) __attribute__ ((signal,__INTR_ATTRS)) 
__VA_ARGS__; \
    void vector (void)
#else
#  define ISR(vector, ...)            \
    void vector (void) __attribute__ ((signal,__INTR_ATTRS)) __VA_ARGS__; \
    void vector (void)
#endif

#endif /* DOXYGEN */

#if defined(__DOXYGEN__)
/** \def SIGNAL(vector)
    \ingroup avr_interrupts

    Introduces an interrupt handler function that runs with global interrupts
    initially disabled.

    This is the same as the ISR macro without optional attributes.
    \deprecated Do not use SIGNAL() in new code. Use ISR() instead.
*/
#  define SIGNAL(vector)
#else  /* real code */

#ifdef __cplusplus
#  define SIGNAL(vector)                                        \
    extern "C" void vector(void) __attribute__ ((signal, __INTR_ATTRS));        
\
    void vector (void)
#else
#  define SIGNAL(vector)                                        \
    void vector (void) __attribute__ ((signal, __INTR_ATTRS));          \
    void vector (void)
#endif

>From ac3304a63bdfbf45f2f6c18e370e81f4292262cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Gr=C3=A9goire=20Jadi?= <gj...@omecha.info>
Date: Tue, 19 Jun 2018 19:53:25 +0200
Subject: [PATCH] Update devel/simulavr to 1.0.0

---
 devel/simulavr/Makefile                            |  14 +-
 devel/simulavr/distinfo                            |   4 +-
 devel/simulavr/patches/patch-configure             |  25 ----
 devel/simulavr/patches/patch-src_cmd_gdbserver_cpp | 147 +++++++++++++++++++++
 devel/simulavr/patches/patch-src_eeprom_c          |  16 ---
 devel/simulavr/patches/patch-src_flash_c           |  16 ---
 devel/simulavr/patches/patch-src_memory_c          |  16 ---
 devel/simulavr/patches/patch-src_systemclock_cpp   |  16 +++
 devel/simulavr/pkg/PLIST                           | 119 +++++++++++++----
 9 files changed, 265 insertions(+), 108 deletions(-)
 delete mode 100644 devel/simulavr/patches/patch-configure
 create mode 100644 devel/simulavr/patches/patch-src_cmd_gdbserver_cpp
 delete mode 100644 devel/simulavr/patches/patch-src_eeprom_c
 delete mode 100644 devel/simulavr/patches/patch-src_flash_c
 delete mode 100644 devel/simulavr/patches/patch-src_memory_c
 create mode 100644 devel/simulavr/patches/patch-src_systemclock_cpp

diff --git a/devel/simulavr/Makefile b/devel/simulavr/Makefile
index ec274bee33e..8c3f7df091e 100644
--- a/devel/simulavr/Makefile
+++ b/devel/simulavr/Makefile
@@ -2,7 +2,7 @@
 
 COMMENT=	AVR simulator
 
-DISTNAME=	simulavr-0.1.2.7
+DISTNAME=	simulavr-1.0.0
 CATEGORIES=	devel
 
 HOMEPAGE=	http://www.nongnu.org/simulavr/
@@ -13,21 +13,21 @@ PERMIT_PACKAGE_CDROM=	Yes
 MASTER_SITES=		${MASTER_SITE_SAVANNAH:=simulavr/}
 
 WANTLIB=		c ncurses
+SHARED_LIBS += sim 		0.0
 
 CONFIGURE_STYLE= 	gnu
-CONFIGURE_ARGS+=	--enable-curses=yes \
-			--disable-versioned-doc
+CONFIGURE_ARGS+=	--with-bfd=${LOCALBASE}
 
+MAKE_FLAGS= LANGUAGES="c c++" CFLAGS="-Wnomacro-redefined"
 USE_GMAKE=		Yes
 
 BUILD_DEPENDS=		${RUN_DEPENDS} \
 			textproc/texi2html \
-			print/texlive/base
+			print/texlive/base \
+			devel/swig
+
 RUN_DEPENDS=		devel/avr/binutils \
 			devel/avr/gcc \
 			devel/avr/libc
 
-pre-configure:
-	${SUBST_CMD} ${WRKSRC}/test_c/Makefile.in
-
 .include <bsd.port.mk>
diff --git a/devel/simulavr/distinfo b/devel/simulavr/distinfo
index e4a024168c7..9b42fe51db7 100644
--- a/devel/simulavr/distinfo
+++ b/devel/simulavr/distinfo
@@ -1,2 +1,2 @@
-SHA256 (simulavr-0.1.2.7.tar.gz) = ypKEDjBNjfr1IZ5kxzqzWtaOxSjgWXaV9ijfYCbwFos=
-SIZE (simulavr-0.1.2.7.tar.gz) = 495892
+SHA256 (simulavr-1.0.0.tar.gz) = Odk/qj7q4r7hX2gt1qSPtNQ2at3RKiq+uwTJn4eAm+c=
+SIZE (simulavr-1.0.0.tar.gz) = 1013014
diff --git a/devel/simulavr/patches/patch-configure b/devel/simulavr/patches/patch-configure
deleted file mode 100644
index 70d8d853766..00000000000
--- a/devel/simulavr/patches/patch-configure
+++ /dev/null
@@ -1,25 +0,0 @@
-$OpenBSD: patch-configure,v 1.2 2017/05/02 19:28:25 rsadowski Exp $
---- configure.orig	Sun Jul  3 11:13:03 2011
-+++ configure	Wed Apr 26 07:45:39 2017
-@@ -6267,7 +6267,7 @@ fi
- 
- { $as_echo "$as_me:${as_lineno-$LINENO}: checking for doxygen" >&5
- $as_echo_n "checking for doxygen... " >&6; }
--dox_ver=`doxygen --version 2>/dev/null`
-+dox_ver=``
- if test "x$dox_ver" = "x"; then
- 	{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
- $as_echo "no" >&6; }
-@@ -6323,9 +6323,9 @@ fi
- 
- 
- # If we are compiling with gcc, enable all warning and make warnings errors.
--if test "$GCC" = yes; then
--    ENABLE_WARNINGS="-Wall -Winline -Werror"
--fi
-+#if test "$GCC" = yes; then
-+#    ENABLE_WARNINGS="-Wall -Winline -Werror"
-+#fi
- ENABLE_WARNINGS=$ENABLE_WARNINGS
- 
- 
diff --git a/devel/simulavr/patches/patch-src_cmd_gdbserver_cpp b/devel/simulavr/patches/patch-src_cmd_gdbserver_cpp
new file mode 100644
index 00000000000..7f7699bc09f
--- /dev/null
+++ b/devel/simulavr/patches/patch-src_cmd_gdbserver_cpp
@@ -0,0 +1,147 @@
+$OpenBSD$
+
+Remove `using namespace std` directive because of a conflict between
+std::bind() and bind(2).
+
+Index: src/cmd/gdbserver.cpp
+--- src/cmd/gdbserver.cpp.orig
++++ src/cmd/gdbserver.cpp
+@@ -24,7 +24,6 @@
+  */
+ 
+ #include <iostream>
+-using namespace std;
+ 
+ #include <assert.h>
+ #include <stdio.h>
+@@ -310,7 +309,7 @@ GdbServer::GdbServer(AvrDevice *c, int _port, int debu
+ }
+ 
+ //make the instance of static list of all gdb servers here
+-vector<GdbServer*> GdbServer::allGdbServers;
++std::vector<GdbServer*> GdbServer::allGdbServers;
+ 
+ GdbServer::~GdbServer() {
+     server->Close();
+@@ -1008,43 +1007,43 @@ void GdbServer::gdb_break_point(const char *pkt) {
+ 
+             if (z == 'z') 
+             {
+-                //cout << "Try to UNSET a software breakpoint" << endl;
+-                //cout << "at address :" << addr << " with len " << len << endl;
++                //std::cout << "Try to UNSET a software breakpoint" << std::endl;
++                //std::cout << "at address :" << addr << " with len " << len << std::endl;
+                 avr_core_remove_breakpoint( addr/2 );
+             }
+             else
+             {
+-                //cout << "Try to SET a software breakpoint" << endl;
+-                //cout << "at address :" << addr << " with len " << len << endl;
++                //std::cout << "Try to SET a software breakpoint" << std::endl;
++                //std::cout << "at address :" << addr << " with len " << len << std::endl;
+                 avr_core_insert_breakpoint( addr/2 );
+             }
+             break;
+ 
+         case '1':               /* hardware breakpoint */
+-            //cout << "Try to set a hardware breakpoint" << endl;
+-            //cout << "at address :" << addr << " with len " << len << endl;
++            //std::cout << "Try to set a hardware breakpoint" << std::endl;
++            //std::cout << "at address :" << addr << " with len " << len << std::endl;
+ 
+             gdb_send_reply( "" );
+             return;
+             break;
+ 
+         case '2':               /* write watchpoint */
+-            //cout << "Try to set a watchpoint" << endl;
+-            //cout << "at address :" << addr << " with len " << len << endl;
++            //std::cout << "Try to set a watchpoint" << std::endl;
++            //std::cout << "at address :" << addr << " with len " << len << std::endl;
+             gdb_send_reply( "" );
+             return;
+             break;
+ 
+         case '3':               /* read watchpoint */
+-            //cout << "Try to set a read watchpoint" << endl;
+-            //cout << "at address :" << addr << " with len " << len << endl;
++            //std::cout << "Try to set a read watchpoint" << std::endl;
++            //std::cout << "at address :" << addr << " with len " << len << std::endl;
+             gdb_send_reply( "" );
+             return;
+             break;
+ 
+         case '4':               /* access watchpoint */
+-            //cout << "try to set a access watchpoint" << endl;
+-            //cout << "at address :" << addr << " with len " << len << endl;
++            //std::cout << "try to set a access watchpoint" << std::endl;
++            //std::cout << "at address :" << addr << " with len " << len << std::endl;
+             gdb_send_reply( "" );
+             return;             /* unsupported yet */
+     }
+@@ -1439,7 +1438,7 @@ int GdbServer::Step(bool &trueHwStep, SystemClockOffse
+ 
+ void GdbServer::IdleStep() {
+     int gdbRet=gdb_receive_and_process_packet(GDB_BLOCKING_OFF);
+-    cout << "IdleStep Instance" << this << " RunMode:" << dec << runMode << endl;
++    std::cout << "IdleStep Instance" << this << " RunMode:" << std::dec << runMode << std::endl;
+ 
+     if (lastCoreStepFinished) {
+         switch(gdbRet) {
+@@ -1459,20 +1458,20 @@ void GdbServer::IdleStep() {
+                 break;
+ 
+             default:
+-                cout << "wondering" << endl;
++                std::cout << "wondering" << std::endl;
+         }
+     }
+ }
+ 
+ int GdbServer::InternalStep(bool &untilCoreStepFinished, SystemClockOffset *timeToNextStepIn_ns) {
+-    //cout << "Internal Step entered" << endl;
+-    //cout << "RunMode: " << dec << runMode << endl;
++    //std::cout << "Internal Step entered" << std::endl;
++    //std::cout << "RunMode: " << std::dec << runMode << std::endl;
+ 
+     if (lastCoreStepFinished) {
+         bool leave;
+ 
+         do {
+-            //cout << "Loop" << endl;
++            //std::cout << "Loop" << std::endl;
+             int gdbRet=gdb_receive_and_process_packet((runMode==GDB_RET_CONTINUE) ? GDB_BLOCKING_OFF : GDB_BLOCKING_ON);
+ 
+             switch (gdbRet) { //GDB_RESULT TYPES
+@@ -1484,17 +1483,17 @@ int GdbServer::InternalStep(bool &untilCoreStepFinishe
+                     break;
+ 
+                 case GDB_RET_CONTINUE:
+-                    //cout << "############################################################ gdb continue" << endl;
++                    //std::cout << "############################################################ gdb continue" << std::endl;
+                     runMode=GDB_RET_CONTINUE;       //lets continue until we receive something from gdb (normal CTRL-C)
+                     break;                          //or we run into a break point or illegal instruction
+ 
+                 case GDB_RET_SINGLE_STEP:
+-                    //cout << "############################################################# Single Step" << endl;
++                    //std::cout << "############################################################# Single Step" << std::endl;
+                     runMode=GDB_RET_SINGLE_STEP;
+                     break;
+ 
+                 case GDB_RET_CTRL_C:
+-                    //cout << "############################################################# CTRL C" << endl;
++                    //std::cout << "############################################################# CTRL C" << std::endl;
+                     runMode=GDB_RET_CTRL_C;
+                     SendPosition(GDB_SIGINT); //Give gdb an idea where the core is now 
+                     break;
+@@ -1515,8 +1514,8 @@ int GdbServer::InternalStep(bool &untilCoreStepFinishe
+ 
+             if(!leave) { //we can�t leave the loop so we have to request the other gdb instances now!
+                 // step through all gdblist members WITHOUT my self!
+-                //cout << "we do not leave and check for gdb events" << endl;
+-                vector<GdbServer*>::iterator ii;
++                //std::cout << "we do not leave and check for gdb events" << std::endl;
++                std::vector<GdbServer*>::iterator ii;
+                 for (ii=allGdbServers.begin(); ii!=allGdbServers.end(); ii++) {
+                     if (*ii!=this) { //run other instances but not me 
+                         (*ii)->IdleStep();
diff --git a/devel/simulavr/patches/patch-src_eeprom_c b/devel/simulavr/patches/patch-src_eeprom_c
deleted file mode 100644
index ea181240eb3..00000000000
--- a/devel/simulavr/patches/patch-src_eeprom_c
+++ /dev/null
@@ -1,16 +0,0 @@
-$OpenBSD: patch-src_eeprom_c,v 1.1 2011/03/14 22:27:02 jasper Exp $
-
-Fix buffer overflow due to incorrect strncat() usage.
-http://savannah.nongnu.org/bugs/?29049
-
---- src/eeprom.c.orig	Mon Mar 14 23:22:50 2011
-+++ src/eeprom.c	Mon Mar 14 23:25:25 2011
-@@ -416,7 +416,7 @@ eeprom_dump_core (EEProm *eeprom, FILE * f_core)
-             line[0] = '\0';
-         }
-         snprintf (buf, 80, "%02x ", storage_readb (eeprom->stor, i));
--        strncat (line, buf, 80);
-+        strncat (line, buf, 80 - strlen(line) - 1);
-     }
-     if (dup > 0)
-     {
diff --git a/devel/simulavr/patches/patch-src_flash_c b/devel/simulavr/patches/patch-src_flash_c
deleted file mode 100644
index f17d219a785..00000000000
--- a/devel/simulavr/patches/patch-src_flash_c
+++ /dev/null
@@ -1,16 +0,0 @@
-$OpenBSD: patch-src_flash_c,v 1.1 2011/03/14 22:27:02 jasper Exp $
-
-Fix buffer overflow due to incorrect strncat() usage.
-http://savannah.nongnu.org/bugs/?29049
-
---- src/flash.c.orig	Mon Mar 14 23:23:00 2011
-+++ src/flash.c	Mon Mar 14 23:25:14 2011
-@@ -252,7 +252,7 @@ flash_dump_core (Flash *flash, FILE * f_core)
-             line[0] = '\0';
-         }
-         snprintf (buf, 80, "%04x ", flash_read (flash, i));
--        strncat (line, buf, 80);
-+        strncat (line, buf, 80 - strlen(line) - 1);
-     }
-     if (dup > 0)
-     {
diff --git a/devel/simulavr/patches/patch-src_memory_c b/devel/simulavr/patches/patch-src_memory_c
deleted file mode 100644
index 4f1726f021a..00000000000
--- a/devel/simulavr/patches/patch-src_memory_c
+++ /dev/null
@@ -1,16 +0,0 @@
-$OpenBSD: patch-src_memory_c,v 1.1 2011/03/14 22:27:02 jasper Exp $
-
-Fix buffer overflow due to incorrect strncat() usage.
-http://savannah.nongnu.org/bugs/?29049
-
---- src/memory.c.orig	Mon Mar 14 23:22:55 2011
-+++ src/memory.c	Mon Mar 14 23:25:21 2011
-@@ -424,7 +424,7 @@ mem_sram_display (Memory *mem, FILE * f_core, int base
-             line[0] = '\0';
-         }
-         snprintf (buf, 80, "%02x ", mem_read (mem, i));
--        strncat (line, buf, 80);
-+        strncat (line, buf, 80 - strlen(line) - 1);
-     }
-     if (dup > 0)
-     {
diff --git a/devel/simulavr/patches/patch-src_systemclock_cpp b/devel/simulavr/patches/patch-src_systemclock_cpp
new file mode 100644
index 00000000000..7c4a715c2b8
--- /dev/null
+++ b/devel/simulavr/patches/patch-src_systemclock_cpp
@@ -0,0 +1,16 @@
+$OpenBSD$
+
+clang is more strict than gcc during the two-phase name lookup
+
+Index: src/systemclock.cpp
+--- src/systemclock.cpp.orig
++++ src/systemclock.cpp
+@@ -67,7 +67,7 @@ bool MinHeap<Key, Value>::ContainsValue(Value v) const
+ template<typename Key, typename Value>
+ void MinHeap<Key, Value>::Insert(Key k, Value v)
+ {
+-	resize(this->size()+1);
++    this->resize(this->size()+1);
+ 	for(unsigned i = this->size();;) {
+ 		unsigned parent = i/2;
+ 		if(parent == 0 || (*this)[parent-1].first < k) {
diff --git a/devel/simulavr/pkg/PLIST b/devel/simulavr/pkg/PLIST
index 585762d5856..dc18f9da035 100644
--- a/devel/simulavr/pkg/PLIST
+++ b/devel/simulavr/pkg/PLIST
@@ -1,35 +1,102 @@
-@comment $OpenBSD: PLIST,v 1.4 2017/05/02 19:28:25 rsadowski Exp $
+@comment $OpenBSD: PLIST,v$
 @bin bin/simulavr
-@bin bin/simulavr-disp
-@bin bin/simulavr-vcd
-info/simulavr.info
-@man man/man1/simulavr-disp.1
-@man man/man1/simulavr.1
+include/simulavr/
+include/simulavr/adcpin.h
+include/simulavr/application.h
+include/simulavr/at4433.h
+include/simulavr/at8515.h
+include/simulavr/at90canbase.h
+include/simulavr/atmega128.h
+include/simulavr/atmega1284abase.h
+include/simulavr/atmega16_32.h
+include/simulavr/atmega668base.h
+include/simulavr/atmega8.h
+include/simulavr/attiny2313.h
+include/simulavr/avrdevice.h
+include/simulavr/avrdevice_impl.h
+include/simulavr/avrerror.h
+include/simulavr/avrfactory.h
+include/simulavr/avrmalloc.h
+include/simulavr/breakpoint.h
+include/simulavr/config_deprecated.h
+include/simulavr/decoder.h
+include/simulavr/dumpargs.h
+include/simulavr/externalirq.h
+include/simulavr/externaltype.h
+include/simulavr/extpin.h
+include/simulavr/flash.h
+include/simulavr/flashprog.h
+include/simulavr/funktor.h
+include/simulavr/gdb.h
+include/simulavr/global.h
+include/simulavr/hardware.h
+include/simulavr/helper.h
+include/simulavr/hwacomp.h
+include/simulavr/hwad.h
+include/simulavr/hwdecls.h
+include/simulavr/hweeprom.h
+include/simulavr/hwpinchange.h
+include/simulavr/hwport.h
+include/simulavr/hwspi.h
+include/simulavr/hwsreg.h
+include/simulavr/hwstack.h
+include/simulavr/hwtimer.h
+include/simulavr/hwuart.h
+include/simulavr/hwwado.h
+include/simulavr/icapturesrc.h
+include/simulavr/ioregs.h
+include/simulavr/irqsystem.h
+include/simulavr/keyboard.h
+include/simulavr/keynumber_to_scancode.dat
+include/simulavr/keytrans.h
+include/simulavr/lcd.h
+include/simulavr/memory.h
+include/simulavr/mysocket.h
+include/simulavr/net.h
+include/simulavr/pin.h
+include/simulavr/pinatport.h
+include/simulavr/pinmon.h
+include/simulavr/pinnotify.h
+include/simulavr/prescalermux.h
+include/simulavr/printable.h
+include/simulavr/pysimulationmember.h
+include/simulavr/rwmem.h
+include/simulavr/scope.h
+include/simulavr/serialrx.h
+include/simulavr/serialtx.h
+include/simulavr/simulationmember.h
+include/simulavr/specialmem.h
+include/simulavr/spisink.h
+include/simulavr/spisrc.h
+include/simulavr/string2.h
+include/simulavr/string2_template.h
+include/simulavr/systemclock.h
+include/simulavr/systemclocktypes.h
+include/simulavr/timerirq.h
+include/simulavr/timerprescaler.h
+include/simulavr/traceval.h
+include/simulavr/types.h
+include/simulavr/ui.h
+include/simulavr/xcode_to_keynumber.dat
+lib/libsim.a
+lib/libsim.la
+@lib lib/libsim.so.${LIBsim_VERSION}
 share/doc/simulavr/
 share/doc/simulavr/AUTHORS
 share/doc/simulavr/COPYING
 share/doc/simulavr/ChangeLog
-share/doc/simulavr/ChangeLog-2001
-share/doc/simulavr/ChangeLog-2002
-share/doc/simulavr/ChangeLog-2003
 share/doc/simulavr/INSTALL
-share/doc/simulavr/ProjSummary
+share/doc/simulavr/NEWS
 share/doc/simulavr/README
 share/doc/simulavr/README.gdb
-share/doc/simulavr/README.opcodes
+share/doc/simulavr/SUPPORT
 share/doc/simulavr/TODO
-share/doc/simulavr/html/
-share/doc/simulavr/html/index.html
-share/doc/simulavr/html/simulavr.html
-share/doc/simulavr/html/simulavr_1.html
-share/doc/simulavr/html/simulavr_10.html
-share/doc/simulavr/html/simulavr_2.html
-share/doc/simulavr/html/simulavr_3.html
-share/doc/simulavr/html/simulavr_4.html
-share/doc/simulavr/html/simulavr_5.html
-share/doc/simulavr/html/simulavr_6.html
-share/doc/simulavr/html/simulavr_7.html
-share/doc/simulavr/html/simulavr_8.html
-share/doc/simulavr/html/simulavr_9.html
-share/doc/simulavr/html/simulavr_abt.html
-share/doc/simulavr/html/simulavr_toc.html
+share/doc/simulavr/examples/
+share/doc/simulavr/examples/ChangeLog
+share/doc/simulavr/examples/gui.tcl
+share/doc/simulavr/examples/kbd.xbm
+share/doc/simulavr/examples/simple_ex1/
+share/doc/simulavr/examples/simple_ex1/README
+share/doc/simulavr/examples/simple_ex1/fred.c
+share/doc/simulavr/examples/simple_ex1/fred.elf
+share/doc/simulavr/examples/simulavr.tcl
-- 
2.16.4

> Since the introduction of retguard, devel/simulavr has continuously
> failed to build on amd64.  This is actually a bug in devel/avr/gcc.
> The problem was diagnosed early by mortimer@.  As I'm not making
> any progress, I'm forwarding his analysis here to give other people
> a chance to help out.
>
> ------------------------------------------------------------------------
> Date: Wed, 9 May 2018 21:58:47 -0400
> From: Todd Mortimer <t...@opennet.ca>
> To: Christian Weisgerber <na...@mips.inka.de>
> Cc: es...@openbsd.org
> Subject: Re: Retguard needs a ports run
>
>> build failure that happened again when I re-tried: devel/simulavr
>>
>> avr-gcc  -I. -I../src -I.     -g -Wall -mmcu=atmega128 -MT timer.o -MD -MP 
>> -MF .deps/timer.Tpo -c -o timer.o timer.c
>> avr-gcc: Internal error: Abort trap (program cc1)
>>
>> I'm skeptical that this has anything to do with retguard, but it
>> is unexpected.
>
> This isn't a retguard failure - it's a buffer overwrite by one. The
> overwrite smashes the stack protector, so the Abort is coming from the
> stack smash handler:
>
>>>> bt
> #0  thrkill () at -:3
> #1  0x00000e789907db2c in __stack_smash_handler (func=<optimized out>, 
> damaged=<optimized out>) at /usr/src/lib/libc/sys/stack_protector.c:79
> #2  0x00000e7667e2bdb2 in df_record_exit_block_uses ()
> #3  0x00000e7667e313b7 in df_update_exit_block_uses ()
> #4  0x00000e7667e2f44f in df_update_entry_exit_and_calls ()
> #5  0x00000e7667f0a95c in thread_prologue_and_epilogue_insns ()
> #6  0x00000e7667f05524 in rest_of_handle_thread_prologue_and_epilogue ()
> #7  0x00000e7667fa3213 in execute_one_pass ()
> #8  0x00000e7667fa2e9f in execute_pass_list ()
> #9  0x00000e7667fa2ec7 in execute_pass_list ()
> #10 0x00000e7667fa2ec7 in execute_pass_list ()
> #11 0x00000e76680ccea6 in tree_rest_of_compilation ()
> #12 0x00000e766827ac77 in cgraph_expand_function ()
> #13 0x00000e766827b541 in cgraph_assemble_pending_functions ()
> #14 0x00000e766827a9bd in cgraph_finalize_function ()
> #15 0x00000e7667d14a8b in finish_function ()
> #16 0x00000e7667d83b2b in c_parser_declaration_or_fndef ()
> #17 0x00000e7667d8276f in c_parser_external_declaration ()
> #18 0x00000e7667d818b7 in c_parser_translation_unit ()
> #19 0x00000e7667d81617 in c_parse_file ()
> #20 0x00000e7667d73022 in c_common_parse_file ()
> #21 0x00000e76680680d1 in compile_file ()
> #22 0x00000e7668066f35 in do_compile ()
> #23 0x00000e7668066bc9 in toplev_main ()
> #24 0x00000e7667d9d4ff in main ()
>
> I stepped through the code to see where it was dying. It's like this:
>
> - df_record_exit_block_uses() has a buffer on the stack
>
> - it calls df_exit_block_uses_collect(), which iterates through the buffer
>   setting entries.
>
> - Before returning, df_exit_block_uses_collect() calls
>   df_canonize_collection_rec(), which null terminates the buffer, which
>   happens to null terminate just past the end of the buffer, which just
>   happens to be the stack cookie.
>
> - The cookie check fails, and it dies.
>
> So it seems that the way that retguard is responsible for this is
> because retguard changes the stack frame layout a bit, and the stack
> cookie happens to be immediately next to the buffer now, and now it gets
> whacked. This shouldn't be too hard to patch - it's just a buffer
> overflow.
>
> Thanks again!
>
> :-)
> Todd

Reply via email to