Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
198 changes: 7 additions & 191 deletions run_build.pl
Original file line number Diff line number Diff line change
Expand Up @@ -1141,7 +1141,13 @@ END
{
print time_str(), "running find_typedefs ...\n" if $verbose;

find_typedefs();
my (@foundsyms);
my $source = $from_source || '../pgsql';

@foundsyms = run_log("perl $source/src/tools/find_typedefs.pl");

writelog('typedefs', \@foundsyms);
$steps_completed .= " find-typedefs";
}

# if we get here everything went fine ...
Expand Down Expand Up @@ -2577,196 +2583,6 @@ sub make_ecpg_check
return;
}

# replace previous use of external egrep -A
sub _dump_filter
{
my ($lines, $tag, $context) = @_;
my @output;
while (@$lines)
{
my $line = shift @$lines;
if (index($line, $tag) > -1)
{
push(@output, splice(@$lines, 0, $context));
}
}
return @output;
}

sub find_typedefs
{
# work around the fact that ucrt/binutils objdump is far slower
# than the one in msys/binutils
local $ENV{PATH} = $ENV{PATH};
$ENV{PATH} = "/usr/bin:$ENV{PATH}" if $Config{osname} eq 'msys';

my ($hostobjdump) = grep { /--host=/ } @$config_opts;
$hostobjdump ||= "";
$hostobjdump =~ s/--host=(.*)/$1-objdump/;
my $objdump = 'objdump';
my $sep = $using_msvc ? ';' : ':';

# if we have a hostobjdump, find out which of it and objdump is in the path
foreach my $p (split(/$sep/, $ENV{PATH}))
{
last unless $hostobjdump;
last if (-e "$p/objdump" || -e "$p/objdump.exe");
if (-e "$p/$hostobjdump" || -e "$p/$hostobjdump.exe")
{
$objdump = $hostobjdump;
last;
}
}
my @err = `$objdump -W 2>&1`;
my @readelferr = `readelf -w 2>&1`;
my $using_osx = (`uname` eq "Darwin\n");
my @testfiles;
my %syms;
my @dumpout;
my @flds;

if ($using_osx)
{

# On OS X, we need to examine the .o files
# exclude ecpg/test, which pgindent does too
my $obj_wanted = sub {
/^.*\.o\z/s
&& !($File::Find::name =~ m!/ecpg/test/!s)
&& push(@testfiles, $File::Find::name);
};

File::Find::find($obj_wanted, $pgsql);
}
else
{

# Elsewhere, look at the installed executables and shared libraries
@testfiles = (
glob("$installdir/bin/*"),
glob("$installdir/lib/*"),
glob("$installdir/lib/postgresql/*")
);
}
foreach my $bin (@testfiles)
{
next if $bin =~ m!bin/(ipcclean|pltcl_)!;
next unless -f $bin;
next if -l $bin; # ignore symlinks to plain files
next if $bin =~ m!/postmaster.exe$!; # sometimes a copy not a link

if ($using_osx)
{
# no run_log due to redirections.
@dumpout = `dwarfdump $bin 2>/dev/null`;
@dumpout = _dump_filter(\@dumpout, 'TAG_typedef', 2);
foreach (@dumpout)
{
## no critic (RegularExpressions::ProhibitCaptureWithoutTest)
@flds = split;
if (@flds == 3)
{
# old format
next unless ($flds[0] eq "AT_name(");
next unless ($flds[1] =~ m/^"(.*)"$/);
$syms{$1} = 1;
}
elsif (@flds == 2)
{
# new format
next unless ($flds[0] eq "DW_AT_name");
next unless ($flds[1] =~ m/^\("(.*)"\)$/);
$syms{$1} = 1;
}
}
}
elsif (@err == 1) # Linux and sometimes windows
{
my $cmd = "$objdump -Wi $bin 2>/dev/null";
@dumpout = `$cmd`; # no run_log because of redirections
@dumpout = _dump_filter(\@dumpout, 'DW_TAG_typedef', 3);
foreach (@dumpout)
{
@flds = split;
next unless (1 < @flds);
next
if (($flds[0] ne 'DW_AT_name' && $flds[1] ne 'DW_AT_name')
|| $flds[-1] =~ /^DW_FORM_str/);
$syms{ $flds[-1] } = 1;
}
}
elsif (@readelferr > 10)
{

# FreeBSD, similar output to Linux
my $cmd = "readelf -w $bin 2>/dev/null";
@dumpout = ` $cmd`; # no run_log due to redirections
@dumpout = _dump_filter(\@dumpout, 'DW_TAG_typedef', 3);

foreach (@dumpout)
{
@flds = split;
next unless (1 < @flds);
next if ($flds[0] ne 'DW_AT_name');
$syms{ $flds[-1] } = 1;
}
}
else
{
# no run_log due to redirections.
@dumpout = `$objdump --stabs $bin 2>/dev/null`;
foreach (@dumpout)
{
@flds = split;
next if (@flds < 7);
next if ($flds[1] ne 'LSYM' || $flds[6] !~ /([^:]+):t/);
## no critic (RegularExpressions::ProhibitCaptureWithoutTest)
$syms{$1} = 1;
}
}
}
my @badsyms = grep { /\s/ } keys %syms;
push(@badsyms, 'date', 'interval', 'timestamp', 'ANY');
delete @syms{@badsyms};

my @goodsyms = sort keys %syms;
my @foundsyms;

my %foundwords;

my $setfound = sub {

# $_ is the name of the file being examined
# its directory is our current cwd

return unless (-f $_ && /^.*\.[chly]\z/);

my $src = file_contents($_);

# strip C comments
# We used to use the recipe in perlfaq6 but there is actually no point.
# We don't need to keep the quoted string values anyway, and
# on some platforms the complex regex causes perl to barf and crash.
$src =~ s{/\*.*?\*/}{}gs;

foreach my $word (split(/\W+/, $src))
{
$foundwords{$word} = 1;
}
};

File::Find::find($setfound, "$branch_root/pgsql");

foreach my $sym (@goodsyms)
{
push(@foundsyms, "$sym\n") if exists $foundwords{$sym};
}

writelog('typedefs', \@foundsyms);
$steps_completed .= " find-typedefs";
return;
}

# meson setup for all platforms
sub meson_setup
{
Expand Down