From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26756 invoked by alias); 14 Jun 2002 23:15:13 -0000 Mailing-List: contact ecos-discuss-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@sources.redhat.com Received: (qmail 26748 invoked from network); 14 Jun 2002 23:15:11 -0000 Received: from unknown (HELO e31.co.us.ibm.com) (32.97.110.129) by sources.redhat.com with SMTP; 14 Jun 2002 23:15:11 -0000 Received: from westrelay04.boulder.ibm.com (westrelay04.boulder.ibm.com [9.17.192.94]) by e31.co.us.ibm.com (8.12.2/8.12.2) with ESMTP id g5ENFAcx008710; Fri, 14 Jun 2002 19:15:10 -0400 Received: from d03nm041.boulder.ibm.com (d03nm041h.boulder.ibm.com [9.17.194.41]) by westrelay04.boulder.ibm.com (8.11.1m3/NCO/VER6.1) with ESMTP id g5ENEEj64504; Fri, 14 Jun 2002 17:14:14 -0600 To: Larice Robert Cc: ecos-discuss@sources.redhat.com MIME-Version: 1.0 From: "Stephen Morgan" Message-ID: Date: Fri, 14 Jun 2002 16:15:00 -0000 Content-Type: text/plain; charset="us-ascii" Subject: Re: [ECOS] bug allert, variable alignment problem in ecos X-SW-Source: 2002-06/txt/msg00259.txt.bz2 Sorry for the slow reply. I cheated. For cases in which I found the problem -- luckily, there weren't all that many --, I told gcc to align the C and C++ fields on a large enough boundary that the layouts matched. For example, I changed kapidata.h to align fields in the thread data structures. First, I added a macro that allowed me to align a field using gcc's "attribute" capability for my platform (which I'll call "blech"): #ifdef CYGPKG_HAL_BLECH #define CYGPKG_HAL_ALIGNED __attribute__ ((aligned (8))) #else // ! CYGPKG_HAL_BLECH #define CYGPKG_HAL_ALIGNED #endif // CYKPKG_HAL_BLECH Then, I used the macro to align fields that weren't otherwise properly aligned. For example, I changed CYG_THREADTIMER_MEMBERS from: #define CYG_THREADTIMER_MEMBERS \ CYG_ALARM_MEMBERS \ cyg_thread *thread; to: #define CYG_THREADTIMER_MEMBERS \ CYG_ALARM_MEMBERS \ cyg_thread *thread CYGPKG_HAL_ALIGNED ; It wasn't pretty, but it worked and we had to meet a deadline... (BTW, I couldn't readily cut and paste from the source to this note, so I typed in the above. It may contain errors!) Stephen P. Morgan Larice Robert 06/14/2002 04:03 AM To: Stephen Morgan/Almaden/IBM@IBMUS cc: ecos-discuss@sources.redhat.com Subject: Re: [ECOS] bug allert, variable alignment problem in ecos Hello Stephen, how did you deal with this, did you stop the project, did you find a solution, or did you just live with the linker lottery. most of the time you wont notice the problem, because most global objects are aligned to 4 byte. so if there are just few in-between, you have a good chance to be lucky. actually the problem i've described is not C++ specific. though the want to allocate space for some class object, and the want to avoid constructor calling, has led to some char space[sizeof(class ..)]; in the ecos tree, which is another manifestation of the alignment problem. to extend your aside, for me too, the decision to use C++ for the bit-tiddling internals of an embedded realtime os is a bit unexpected. but with great care can be done, and has merits too. anyway, i've sent a patch for almost 200 dangerous global variables to ecos-patches. (though most of them are in some test directories, and thus of minor significance. those will even be helpfull to get accustomed with the debugger) Robert Larice > Yes. We saw the problem in debugging eCos on a MIPS32 processor and it > drove us crazy. It showed up especially in threads structures as these > are shared between C and C++ code, which apparently have different > alignment rules. > > As an aside, I'm a dyed in the wool C programmer, and find C++ a miserable > language. Why would anyone mix C and C++ within an operating system? Of > course, I use vi as I find emacs incomprehensible, which may indicate > something about my sensibilities -- or merely my abilities... 8-) > > Stephen P. Morgan -- Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos and search the list archive: http://sources.redhat.com/ml/ecos-discuss