mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-12-22 13:45:38 +00:00
407a281a8e
This reverts commit e4b980c853
.
When a binary links against a .a archive (as opposed to a shared library),
any symbols which are marked as 'weak' get silently dropped. As a result
when the binary later runs, those 'weak' functions have an address of
0x0 and thus crash when run.
This happened with virtlogd and virtlockd because they don't link to
libvirt.so, but instead just libvirt_util.a and libvirt_rpc.a. The
virRandomBits symbols was weak and so left out of the virtlogd &
virtlockd binaries, despite being required by virHashTable functions.
Various other binaries like libvirt_lxc, libvirt_iohelper, etc also
link directly to .a files instead of libvirt.so, so are potentially
at risk of dropping symbols leading to a later runtime crash.
This is normal linker behaviour because a weak symbol is not treated
as undefined, so nothing forces it to be pulled in from the .a You
have to force the linker to pull in weak symbols using -u$SYMNAME
which is not a practical approach.
This risk is silent bad linkage that affects runtime behaviour is
not acceptable for a fix that was merely trying to fix the test
suite. So stop using __weak__ again.
Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
73 lines
1.5 KiB
Perl
73 lines
1.5 KiB
Perl
#!/usr/bin/perl
|
|
|
|
my %noninlined;
|
|
my %mocked;
|
|
|
|
# Functions in public header don't get the noinline annotation
|
|
# so whitelist them here
|
|
$noninlined{"virEventAddTimeout"} = 1;
|
|
|
|
foreach my $arg (@ARGV) {
|
|
if ($arg =~ /\.h$/) {
|
|
#print "Scan header $arg\n";
|
|
&scan_annotations($arg);
|
|
} elsif ($arg =~ /mock\.c$/) {
|
|
#print "Scan mock $arg\n";
|
|
&scan_overrides($arg);
|
|
}
|
|
}
|
|
|
|
my $warned = 0;
|
|
foreach my $func (keys %mocked) {
|
|
next if exists $noninlined{$func};
|
|
|
|
$warned++;
|
|
print STDERR "$func is mocked at $mocked{$func} but missing noinline annotation\n";
|
|
}
|
|
|
|
exit $warned ? 1 : 0;
|
|
|
|
|
|
sub scan_annotations {
|
|
my $file = shift;
|
|
|
|
open FH, $file or die "cannot read $file: $!";
|
|
|
|
my $func;
|
|
while (<FH>) {
|
|
if (/^\s*(\w+)\(/ || /^(?:\w+\*?\s+)+(?:\*\s*)?(\w+)\(/) {
|
|
my $name = $1;
|
|
if ($name !~ /ATTRIBUTE/) {
|
|
$func = $name;
|
|
}
|
|
} elsif (/^\s*$/) {
|
|
$func = undef;
|
|
}
|
|
if (/ATTRIBUTE_NOINLINE/) {
|
|
if (defined $func) {
|
|
$noninlined{$func} = 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
close FH
|
|
}
|
|
|
|
sub scan_overrides {
|
|
my $file = shift;
|
|
|
|
open FH, $file or die "cannot read $file: $!";
|
|
|
|
my $func;
|
|
while (<FH>) {
|
|
if (/^(\w+)\(/ || /^\w+\s*(?:\*\s*)?(\w+)\(/) {
|
|
my $name = $1;
|
|
if ($name =~ /^vir/) {
|
|
$mocked{$name} = "$file:$.";
|
|
}
|
|
}
|
|
}
|
|
|
|
close FH
|
|
}
|