These macros elaborate on BOUNDED_SECTION_(PRE|POST)_LABEL macros,
prepending an optional KEEP(.gnu.linkonce##_sec_) reservation, and a
linker-symbol to address it.
This allows a developer to define a header struct (which must fit with
the section's base struct-type), and could contain:
1- fields whose value is common to the entire set of data-records.
This allows the header & data structs to specialize, complement
each other, and shrink.
2- an uplink pointer to an organizing struct
which refs other related/sub data-tables
header record is addressable via the extern'd header linker-symbol
Once the linker-symbols created by the macro are ref'd extern in code,
that code can compute a record's index (ptr - start) in the "primary"
table, then use it to index into the related/sub tables. Adding a
primary.map_* field foreach sub-table would then allow deduplication
and remapping of that sub-table.
This is aimed at dyndbg's struct _ddebug __dyndbg[] section, whose 3
columns: function, file, module are 50%, 90%, 100% redundant. The
module column is fully recoverable after dynamic_debug_init() saves it
to each ddebug_table.module as the builtin __dyndbg[] table is parsed.
Given that those 3 columns use 24/56 of a prdbg record, a dyndbg=y
kernel with ~5k callsites could save substantially.
Signed-off-by: Jim Cromie <[email protected]>
---
---
include/asm-generic/vmlinux.lds.h | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 85d5d5b203dc..a3b6aa30a525 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -214,6 +214,21 @@
#define BOUNDED_SECTION(_sec) BOUNDED_SECTION_BY(_sec, _sec)
+#define HEADERED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_, _HDR_) \
+ _HDR_##_label_ = .; \
+ KEEP(*(.gnu.linkonce.##_sec_)) \
+ BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_)
+
+#define HEADERED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_, _HDR_) \
+ _label_##_HDR_ = .; \
+ KEEP(*(.gnu.linkonce.##_sec_)) \
+ BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_)
+
+#define HEADERED_SECTION_BY(_sec_, _label_) \
+ HEADERED_SECTION_PRE_LABEL(_sec_, _label_, __start, __stop)
+
+#define HEADERED_SECTION(_sec) HEADERED_SECTION_BY(_sec, _sec)
+
#ifdef CONFIG_TRACE_BRANCH_PROFILING
#define LIKELY_PROFILE() \
BOUNDED_SECTION_BY(_ftrace_annotated_branch, _annotated_branch_profile)
--
2.38.1
From: Jim Cromie <[email protected]>
Date: Wed, 16 Nov 2022 17:20:22 -0700
> These macros elaborate on BOUNDED_SECTION_(PRE|POST)_LABEL macros,
> prepending an optional KEEP(.gnu.linkonce##_sec_) reservation, and a
> linker-symbol to address it.
>
> This allows a developer to define a header struct (which must fit with
> the section's base struct-type), and could contain:
[...]
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index 85d5d5b203dc..a3b6aa30a525 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -214,6 +214,21 @@
>
> #define BOUNDED_SECTION(_sec) BOUNDED_SECTION_BY(_sec, _sec)
>
> +#define HEADERED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_, _HDR_) \
> + _HDR_##_label_ = .; \
> + KEEP(*(.gnu.linkonce.##_sec_)) \
> + BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_)
> +
> +#define HEADERED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_, _HDR_) \
> + _label_##_HDR_ = .; \
> + KEEP(*(.gnu.linkonce.##_sec_)) \
> + BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_)
> +
> +#define HEADERED_SECTION_BY(_sec_, _label_) \
> + HEADERED_SECTION_PRE_LABEL(_sec_, _label_, __start, __stop)
Now HEADERED_SECTION_PRE_LABEL() takes 5 arguments, but this line
passes only 4 to it. This went unnoticed probably due to that the
macro is not used anywhere, thus can't trigger a compiler error.
Would you prefer to fix it yourself or me to send the fix?[*]
> +
> +#define HEADERED_SECTION(_sec) HEADERED_SECTION_BY(_sec, _sec)
> +
> #ifdef CONFIG_TRACE_BRANCH_PROFILING
> #define LIKELY_PROFILE() \
> BOUNDED_SECTION_BY(_ftrace_annotated_branch, _annotated_branch_profile)
> --
> 2.38.1
[*] If it needs fixing at all -- some people over the MLs say that
if there's no trigger, then there's nothing to fix :clownface:
Thanks,
Olek
> From: Jim Cromie <[email protected]>
> Date: Wed, 16 Nov 2022 17:20:22 -0700
>
> > These macros elaborate on BOUNDED_SECTION_(PRE|POST)_LABEL macros,
> > prepending an optional KEEP(.gnu.linkonce##_sec_) reservation, and a
> > linker-symbol to address it.
> >
> > This allows a developer to define a header struct (which must fit with
> > the section's base struct-type), and could contain:
>
> [...]
>
> > diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> > index 85d5d5b203dc..a3b6aa30a525 100644
> > --- a/include/asm-generic/vmlinux.lds.h
> > +++ b/include/asm-generic/vmlinux.lds.h
> > @@ -214,6 +214,21 @@
> >
> > #define BOUNDED_SECTION(_sec) BOUNDED_SECTION_BY(_sec, _sec)
> >
Also, those two pasting ops below:
> > +#define HEADERED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_, _HDR_) \
> > + _HDR_##_label_ = .; \
> > + KEEP(*(.gnu.linkonce.##_sec_)) \
^^
> > + BOUNDED_SECTION_PRE_LABEL(_sec_, _label_, _BEGIN_, _END_)
> > +
> > +#define HEADERED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_, _HDR_) \
> > + _label_##_HDR_ = .; \
> > + KEEP(*(.gnu.linkonce.##_sec_)) \
^^
will produce incorrect results when @_sec_ starts with a dot (not
a rare thing for section names):
HEADERED_SECTION_BY(.entry_sites, _entry_sites)
vmlinux.map:
.entry_sites 0xffffffff83c89ca0 0x37118 load address 0x0000000003c89ca0
0xffffffff83c89ca0 __header_entry_sites = .
*(.gnu.linkonce. .entry_sites)
here ^^^
.entry_sites 0xffffffff83c89ca0 0x37118 vmlinux.o
0xffffffff83cc0db8 __start_entry_sites = .
*(.entry_sites)
0xffffffff83cc0db8 __stop_entry_sites = .
^ as a result, all .entry_sites entries went to the "header" instead
of the "body".
Sorta dangerous stuff as for me, maybe that could be handled
differently?
> > + BOUNDED_SECTION_POST_LABEL(_sec_, _label_, _BEGIN_, _END_)
> > +
> > +#define HEADERED_SECTION_BY(_sec_, _label_) \
> > + HEADERED_SECTION_PRE_LABEL(_sec_, _label_, __start, __stop)
>
> Now HEADERED_SECTION_PRE_LABEL() takes 5 arguments, but this line
> passes only 4 to it. This went unnoticed probably due to that the
> macro is not used anywhere, thus can't trigger a compiler error.
> Would you prefer to fix it yourself or me to send the fix?[*]
>
> > +
> > +#define HEADERED_SECTION(_sec) HEADERED_SECTION_BY(_sec, _sec)
> > +
> > #ifdef CONFIG_TRACE_BRANCH_PROFILING
> > #define LIKELY_PROFILE() \
> > BOUNDED_SECTION_BY(_ftrace_annotated_branch, _annotated_branch_profile)
> > --
> > 2.38.1
>
> [*] If it needs fixing at all -- some people over the MLs say that
> if there's no trigger, then there's nothing to fix :clownface:
>
> Thanks,
> Olek
Thanks,
Olek