4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-28 03:27:46 +08:00
Corinna Vinschen 820c736785 Cygwin: dllfixdbg: improve readability
- formatting
- use array pointer as argument rather than variable arguments
- syntactical fixes
- add comments
- drop unnecessary recomputation of all section VMAs.

Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
2022-02-04 18:27:14 +01:00

81 lines
2.6 KiB
Perl
Executable File

#!/usr/bin/perl
#
# This file is part of Cygwin.
#
# This software is a copyrighted work licensed under the terms of the
# Cygwin license. Please consult the file "CYGWIN_LICENSE" for
# details.
#
use integer;
use strict;
sub xit {
my ( $execit, $cmdline, $verbose ) = @_;
print "+ ", join (' ', @$cmdline), "\n" if ($verbose);
if ($execit) {
exec @{$cmdline} or die "$0: couldn't exec @{$cmdline}[0] - $!\n";
} else {
system @{$cmdline} and die "$0: couldn't exec @{$cmdline}[0] - $!\n";
}
}
my $objdump = shift; # path to objdump
my $objcopy = shift; # path to objcopy
my $pre_dll = shift; # name of input DLL, usually cygwin0.dll
my $dbg_dll = shift; # name of debug section file, usually cygwin1.dbg
my $new_dll = shift; # name of stripped DLL, usually new-cygwin1.dll
my $verbose = shift; # verbose flag, taken from Makefile's $(V)
# Create cygwin1.dbg file
my @create_dbgfile = ( $objcopy,
'-R',
'.gnu_debuglink_overlay',
'--add-gnu-debuglink=/dev/null',
'--only-keep-debug',
$pre_dll,
$dbg_dll );
&xit (0, \@create_dbgfile, $verbose);
# Create stripped new-cygwin1.dll
# The .gnu_debuglink section gets appended
my @create_stripped_dll = ( $objcopy,
'-g',
'--keep-section=.gnu_debuglink_overlay',
'--add-gnu-debuglink=' . $dbg_dll,
$pre_dll,
$new_dll );
&xit (0, \@create_stripped_dll, $verbose);
# Fixup .gnu_debuglink section
my @fixup_debuglink = ( $objcopy );
open (OBJDUMP, '-|', "$objdump --headers $new_dll");
my $overlay_vma;
while (<OBJDUMP>) {
# Fetch line and split
my ($idx, $name, $size, $vma, $lma, $fileoff, $algn)
= /^\s*(\d+)\s+(\.\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*$/;
# skip section flag lines
next if !defined ($idx);
# If we see a .gnu_debuglink_overlay section, use its section vma
# as vma of the .gnu_debuglink section.
if ($name eq '.gnu_debuglink_overlay') {
$overlay_vma = $vma;
# remove .gnu_debuglink_overlay section
push (@fixup_debuglink,
'-R',
'.gnu_debuglink_overlay');
# move .gnu_debuglink to .gnu_debuglink_overlay section slot
push (@fixup_debuglink,
'--change-section-address',
'.gnu_debuglink=0x' . $overlay_vma);
# fix up section flags
push (@fixup_debuglink,
'--set-section-flag',
'.gnu_debuglink=contents,readonly,debug,noload');
}
}
close OBJDUMP;
# If we didn't find a .gnu_debuglink_overlay section, bail out
defined ($overlay_vma) or die "$0: no .gnu_debuglink_overlay section!\n";
push (@fixup_debuglink, $new_dll);
&xit (1, \@fixup_debuglink, $verbose);