diff options
| author | Dmitry Vyukov <dvyukov@google.com> | 2025-01-17 10:39:47 +0100 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2025-01-17 18:09:32 +0000 |
| commit | f2cb035c8f931efff4a020b164e657f16f51934b (patch) | |
| tree | 967cd39fb98171cba878893a41ca461ffa993c8c /pkg/declextract | |
| parent | 38ee454540b9b41d5cc173871dfbf7dd140e8abc (diff) | |
pkg/declextract: remove unused includes and defines
This is nice on its own, but this will also help to prevent
lots of problems when we export more info from the clang tool in future.
The clang tool does not know what will end up in the final descriptions,
so it exports info about all consts that it encounters.
As the result we pull in lots of includes/defines, and lots of kernel
includes/defines are broken or create problems.
So the fewer we have, the better.
Diffstat (limited to 'pkg/declextract')
| -rw-r--r-- | pkg/declextract/declextract.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/pkg/declextract/declextract.go b/pkg/declextract/declextract.go index fdf06b373..9df449b63 100644 --- a/pkg/declextract/declextract.go +++ b/pkg/declextract/declextract.go @@ -16,7 +16,7 @@ import ( ) func Run(out *Output, probe *ifaceprobe.Info, syscallRename map[string][]string, trace io.Writer) ( - []byte, []*Interface, error) { + []byte, []*Interface, map[string]string, error) { ctx := &context{ Output: out, probe: probe, @@ -29,7 +29,7 @@ func Run(out *Output, probe *ifaceprobe.Info, syscallRename map[string][]string, } ctx.processFunctions() ctx.processTypingFacts() - ctx.processConsts() + includeUse := ctx.processConsts() ctx.processEnums() ctx.processStructs() ctx.processSyscalls() @@ -37,7 +37,7 @@ func Run(out *Output, probe *ifaceprobe.Info, syscallRename map[string][]string, ctx.serialize() ctx.finishInterfaces() - return ctx.descriptions.Bytes(), ctx.interfaces, errors.Join(ctx.errs...) + return ctx.descriptions.Bytes(), ctx.interfaces, includeUse, errors.Join(ctx.errs...) } type context struct { @@ -75,7 +75,7 @@ func (ctx *context) trace(msg string, args ...any) { } } -func (ctx *context) processConsts() { +func (ctx *context) processConsts() map[string]string { replaces := map[string]string{ // Arches may use some includes from asm-generic and some from arch/arm. // If the arch used for extract used asm-generic for a header, @@ -85,6 +85,7 @@ func (ctx *context) processConsts() { "include/uapi/asm-generic/sockios.h": "asm/sockios.h", } defineDedup := make(map[string]bool) + includeUse := make(map[string]string) for _, ci := range ctx.Consts { if strings.Contains(ci.Filename, "/uapi/") && !strings.Contains(ci.Filename, "arch/x86/") && strings.HasSuffix(ci.Filename, ".h") { @@ -93,6 +94,7 @@ func (ctx *context) processConsts() { filename = replace } ctx.includes = append(ctx.includes, filename) + includeUse[ci.Name] = filename continue } // Remove duplicate defines (even with different values). Unfortunately we get few of these. @@ -118,6 +120,11 @@ func (ctx *context) processConsts() { "linux/types.h", "net/netlink.h", }, ctx.includes...) + // Also pretend they are used. + includeUse["__NR_read"] = "vdso/bits.h" + includeUse["__NR_write"] = "linux/types.h" + includeUse["__NR_close"] = "net/netlink.h" + return includeUse } func (ctx *context) processEnums() { |
