[riot-devel] RIOT and static initializers in C++

Joakim Gebart joakim.gebart at eistec.se
Sat Sep 27 09:53:36 CEST 2014


I have in a different project used objcopy to rename the main function
of the actual application to something else, in order to run a test
harness setup main before the actual program starts. Using this method
it is not necessary to implement your own C library initialization and
C++ constructors are executed as expected.

Example command line:
objcopy --redefine-sym main=app_main main.o main2.o

Best regards,
Joakim

On Fri, Sep 26, 2014 at 11:56 PM, Ryan Kurte <ryankurte at gmail.com> wrote:
> I was just reading and wondering, would it be easier just to drop main as
> the application name?
>
> So long as it is well documented it shouldn't make a huge difference to the
> user.
> And that way the toolchain should take care of all the initialization it
> needs to.
>
> Cheers,
>
> Ryan
>
> On Sep 23, 2014 6:24 AM, "Ludwig Ortmann" <ludwig.ortmann at fu-berlin.de>
> wrote:
>>
>> Hi pekka,
>>
>>
>>
>> On 22. September 2014 19:56:04 MESZ, Pekka Nikander
>> <pekka.nikander at iki.fi> wrote:
>> >>>>>  __attribute__((constructor)) static void startup(int argc, char
>> >**argv)
>> >
>> >This is probably a stupid question, but why in the first place are you
>> >declaring startup as a constructor? As there are no guarantees (without
>> >priorities) in which order the constructors are called, that is
>> >somewhat unsafe.
>>
>> Because it worked when I first tried it, because I did not know too much
>> about the initialization process, and:
>>
>> >But then, of course, you have to take care of explicitly initialising
>> >anything else that your native runtimes require, that differs slightly
>> >between Linux, FreeBSD and OSX, and requires some work.
>>
>> .. this, after I dug a bit deeper ;)
>>
>> And finally, because this assumption does not hold:
>>
>> >If you want to take care of all initialisations yourself,
>>
>> Really, all this is just to allow "main" as the user application name, so
>> I didn't want to add unnecessary complexity.
>>
>> Cheers, Ludwig
>> _______________________________________________
>> devel mailing list
>> devel at riot-os.org
>> http://lists.riot-os.org/mailman/listinfo/devel
>
>
> _______________________________________________
> devel mailing list
> devel at riot-os.org
> http://lists.riot-os.org/mailman/listinfo/devel
>


More information about the devel mailing list