[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] Shared libraries: startup and cleanup

From: Dmitry Selyutin
Subject: [Tinycc-devel] Shared libraries: startup and cleanup
Date: Fri, 4 Sep 2015 01:30:14 +0300

Hello guys,

first of all I'd like to thank everyone who takes part in tcc development: it's amazing tool and actually the fastest and smallest compiler I know about! I'm glad that I've found it some years ago and especially glad that it is being developed even now.

The question I have is that I write an open-source project, a big library which provides some Unicode functionality as well as portable filesystem functions and various I/O stuff. I write in C89 with the POSIX standard in mind, but Woe32 is supported as well. The only difficulty I met is that I need to find some analogue for GCC's `__attribute__((constructor))' and `__attribute__((destructor))'. This is the absolutely necessary evil, since I want to get path to current directory right before `main()' is called.

These attributes work under gcc and clang; they also seem to work with pcc, though I prefer to use `_Pragma("init")' and `_Pragma("fini")' instead. I even found the way to achieve the same goal in MSVC. However, tcc seems to ignore `__attribute__', so this approach doesn't help.

A quick search approves my own investigations. It is a pity that tcc lacks this feature; I know it is a non-standard but this is the only reliable way to make an automatic library startup/cleanup without forcing user to call some `weird_lib_init()' and `weird_lib_fini' functions. Is this feature hard to implement? I don't know an assembler, I only heard that this functionality is usually achieved via some kind of `.ctors/.dtors' or `.init_array/.fini_array', where pointers to functions (or their code?) are stored (well, for ELF). But probably there may be a simpler way.

I'd also like to help if this problem can be solved without assembler code. If there is anything I can do I'd like to be useful, so please don't hesitate to ask me! Could you please think about implementing this feature?

Thank you for your help!

reply via email to

[Prev in Thread] Current Thread [Next in Thread]