libbsd: Manipulating object files using waf build system

Christian Mauderer christian.mauderer at embedded-brains.de
Tue Aug 9 08:19:13 UTC 2016


Am 02.08.2016 um 08:04 schrieb Christian Mauderer:
> Hello,
> 
> I have a second waf problem beneath the one already discussed in the
> other thread: Is it possible to do some object file manipulation before
> linking? To be exact I would need to rename some of the sections in the
> object files.
> 
> 
> If you want to stop reading, you can do it here. The following is only
> some background Information why this is necessary:
> 
> Currently I'm porting the user space tool pfctl to set up the firewall
> pf to libbsd. For all initialized (zero or value) global or static
> variables I basically use the following method:
> 
> - put all variables into one named linker section
> - save the section before calling the main
> - restore the section after calling main
> 
> I'll add a more detailed description for the method that I used to port
> into the libbsd.txt as soon as I'm finished with the work.
> 
> 
> I have made some changes that I was trying to upstream to FreeBSD. The
> changes are quite similar to the ones for other programs:
> 
> - Make const what can be const.
> - Make global variables static if possible.
> - Move some static variables out of function scope.
> 
> I've suggested these changes on the FreeBSD mailing list here:
> 
> https://lists.freebsd.org/pipermail/freebsd-hackers/2016-July/049772.html
> 
> The last one (moving the static variables out of the functions) was
> necessary so I could easily add an attribute to the variables. Due to
> the fact that it is not really an improvement, it has started some
> discussion:
> 
> https://lists.freebsd.org/pipermail/freebsd-hackers/2016-August/049821.html
> 
> The method described there would not work for us. But we should be able
> to rename some of the sections. Compared to my current method (adding an
> attribute to every variable) this would make it simpler to update to a
> newer version with some changed global variables. So it's worth a try.
> 
> Kind regards,
> 
> Christian Mauderer
> 

Hello,

Sebastian noted a problem with the approach of manipulating the object
files: On some architectures (e.g. PowerPC) there is a small data
section. If we just rename the section inside the object file, this
could have the effect that the variables wouldn't longer be inside the
small data section memory range.

Sebastian described it with some more details on the FreeBSD mailing
list where I started to discuss the patch that pulls out the function
static variables:


https://docs.freebsd.org/cgi/getmsg.cgi?fetch=12034+0+current/freebsd-hackers

I think currently it's not really useful to continue the object file
manipulation approach.

With my current approach (adding a header at the end of each c file)
this could also be a problem with every variable that is not only used
in one c file but in multiple c files. For global variables the
attribute most likely has to be added to the original FreeBSD header.

Kind regards

Christian Mauderer

-- 
--------------------------------------------
embedded brains GmbH
Christian Mauderer
Dornierstr. 4
D-82178 Puchheim
Germany
email: christian.mauderer at embedded-brains.de
Phone: +49-89-18 94 741 - 18
Fax:   +49-89-18 94 741 - 08
PGP: Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.


More information about the devel mailing list