Changes to pfctl to allow easier integration into a library

Sebastian Huber sebastian.huber at embedded-brains.de
Tue Aug 9 06:12:57 UTC 2016



On 08/08/16 16:54, Christian Mauderer wrote:
> Am 02.08.2016 um 07:36 schrieb Christian Mauderer:
>>
>> Am 01.08.2016 um 20:36 schrieb Kristof Provost:
>>> On 1 Aug 2016, at 16:32, Christian Mauderer wrote:
>>>
>>>      Am 01.08.2016 um 16:02 schrieb Kristof Provost:
>>>
>>>          On 1 Aug 2016, at 15:03, Christian Mauderer wrote:
>>>
>>>              Can I improve anything to make the patches more acceptable?
>>>
>>>          Can you explain why
>>>          0003-pfctl-Pull-static-variables-out-of-the-function.patch is
>>>          required?
>>>          I’m not sure I see why you need it.
>>>
>>>      I use roughly the following method for the global variables:
>>>      - I put all initialized (zero or value) variables into a special named
>>>      linker section.
>>>      - In a wrapper around main() I do the following:
>>>      o First save the content of the section to a temporary memory space
>>>      o Execute the original (mostly unchanged) main()
>>>      o After main() finishes, I restore the content of the section
>>>      To simplify a later update to a newer source version, the difference
>>>      between the sources we use and the original FreeBSD sources should be
>>>      minimal. Therefore my attempt to put the variables into a section is
>>>      the
>>>      following:
>>>      I create a header file (i.e. pfctl-data.h) that contains a matching
>>>      declaration of the global variables but with an added gcc attribute
>>>      __attribute__((__section__("my_section_name"))). This header file is
>>>      included at the end of the original pfctl.c.
>>>
>>> Oh.
>>> Ick.
>>> Clever, but … ick.
>>>
>>> I’m not a big fan of this patch, because it makes the code a bit harder
>>> to follow, rather than improving things as most of your other patches do.
>>> I suspect that something similar can be accomplished with a bit of
>>> linker trickery.
>>>
>>> A first idea is to insert two new symbols (e.g. pf_begin/pf_end) in two
>>> separate files, the first before all of the pfctl object files, the
>>> second after them.
>>> This should let you group the .data section of the pfctl globals,
>>> accomplishing what you do here with the *attribute* attribute.
>>>
>>> Regards,
>>> Kristof
>>>
>> Hello Kristof,
>>
>> I agree that my solution is not optimal and that this specific patch
>> does not really improve the code for you. So I'll try to find alternatives.
>>
>> The method you suggested would not work for us. We are using part of the
>> FreeBSD sources as a library that is statically linked with the rest of
>> the system. Using our build process, the order of the object files does
>> not guarantee an order of the symbols. As far as I know a fixed order
>> can only be achieved by the section names.
>>
>> Theoretically it could be possible to get a similar result with some
>> object file manipulation (renaming sections, ...). I'll check if I'm
>> able to use such a solution instead and report back as soon as I can
>> tell you more.
>>
>> Kind regards,
>>
>> Christian Mauderer
>>
> Hello Kristof,
>
> just the promised report: I'm quite convinced that a solution using
> object file manipulation is possible. It only needs some additional work
> (some adaption to our build system) and therefore needs some time. But
> we work toward it. So just ignore the patch 0003.

I think on PowerPC the object file manipulations could turn out to be 
rather difficult, since we would have to change also the relocation 
types. On PowerPC we use the small-data area, so if you have in your 
source code a global variable like

int g;

then the compiler generates small-data area relocations. However, if you use

int g __attribute__((__section__("x")));

then the compiler generates normal relocations. If you simply rename the 
sections in an object file, e.g. from ".sdata" to ".x", then the 
relocations cannot be resolved or are invalid at run-time. I think we 
have to add the section attribute to all global variable declarations at 
least in the RTEMS port of the FreeBSD code.

-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax     : +49 89 189 47 41-09
E-Mail  : sebastian.huber at embedded-brains.de
PGP     : Public key available on request.

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



More information about the freebsd-hackers mailing list