Skip to content

Instantly share code, notes, and snippets.

@evdenis
Created July 14, 2019 12:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evdenis/bf2322d094f0c02c0f60fe0a225848b2 to your computer and use it in GitHub Desktop.
Save evdenis/bf2322d094f0c02c0f60fe0a225848b2 to your computer and use it in GitHub Desktop.
Check that exported symbols in the Linux kernel are global
#!/usr/bin/env perl
# SPDX-License-Identifier: GPL-2.0
# check_static_export.pl - check that exported symbols are global
# (c) 2019 Denis Efremov <efremov@linux.com>
use strict;
use warnings;
foreach (@ARGV) {
my %symb;
foreach (`nm $_`) {
if (m/^(?<addr>[\da-f]++)?\h++(?<type>\w) (?<name>[\w\.]++)$/) {
push @{$symb{$+{name}}}, {
addr => $+{addr},
type => $+{type}
};
} else {
warn "Can't parse the line $_\n";
}
}
foreach (keys %symb) {
if (m/^__ksymtab_(?<name>\w++)$/) {
my $name = $+{name};
if (exists $symb{$name}) {
my $static = 1;
foreach (@{$symb{$name}}) {
if ($_->{type} eq uc($_->{type})) {
$static = 0;
}
}
warn "WARNING: \"$name\" is the static EXPORT_SYMBOL\n"
if $static;
} else {
warn "Can't find symbol $name\n";
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment