[FFmpeg-devel] [PATCH v5 01/10] cbs_h2645: refact, use cbs_h2645_replace_ps to replace cbs_h26*_replace_*ps

Andreas Rheinhardt andreas.rheinhardt at gmail.com
Mon Feb 15 14:32:11 EET 2021


Nuo Mi:
> On Mon, Feb 15, 2021 at 3:45 AM Andreas Rheinhardt <
> andreas.rheinhardt at gmail.com> wrote:
> 
>> Nuo Mi:
>>> From: Mark Thompson <sw at jkqxz.net>
>>>
>>>
>>> -}
>>> +static int cbs_h2645_replace_ps(CodedBitstreamContext *ctx,
>>> +                                CodedBitstreamUnit *unit)
>>> +{
>>> +    typedef struct {
>>> +        int nal_unit_type;
>>> +        int max_count;
>>> +        const char *name;
>>
>> If this were a char name[4], these structs could be put in .rodata
>> instead of .data (or .data.rel.ro) when using position-independent code.
>>
> thanks for the suggestion.
> What's the benifite for this?
> thanks
> 
When one uses position-independent code, the static linker does not know
the runtime address of the strings here, because their position is not
known until runtime. Therefore the static linker has to create
relocations for them which means that it tells the runtime linker that
it should patch up the char * pointer above to point to the real
(offsetted) address of the relevant string. For platforms other than
Windows, these relocations are expensive (see [1]) and the resultant
pages are dirty and can't be shared between processes; furthermore this
process isn't done in a lazy manner, so that even someone who never uses
cbs_h2645 (or cbs at all) will have the dirty pages from the above as
soon as libavcodec is loaded.

- Andreas

[1]:
https://chromium.googlesource.com/chromium/src/+/master/docs/native_relocations.md


More information about the ffmpeg-devel mailing list