2 # Copyright 2006, 2007 Red Hat, Inc.
4 # This file is part of Cygwin.
6 # This software is a copyrighted work licensed under the terms of the
7 # Cygwin license. Please consult the file "CYGWIN_LICENSE" for
13 my $strip = $ARGV[0] eq '-s';
16 my @objcopy = ((shift));
19 xit 0, @objcopy, '-R', '.gnu_debuglink_overlay', '--only-keep-debug', $dll, $dbg;
20 xit 0, @objcopy, '-g', '--add-gnu-debuglink=' . $dbg, $dll;
21 open(OBJDUMP, '-|', "$objdump --headers $dll");
24 my ($idx, $name, $size, $vma, $lma, $fileoff, $algn) = /^\s*(\d+)\s+(\.\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s*$/;
25 if ($name eq '.gnu_debuglink') {
26 push(@objcopy, '--set-section-flag', '.gnu_debuglink=contents,readonly,debug,noload');
27 $idx = $section{'.gnu_debuglink'}{-idx} if defined($section{'.gnu_debuglink'}{-idx});
28 } elsif ($name eq '.gnu_debuglink_overlay') {
29 push (@objcopy, '-R', '.gnu_debuglink_overlay');
30 $section{'.gnu_debuglink'}{-idx} = $idx;
34 $section{$name} = {-idx=>int($idx), -size=>hex($size), -vma=>hex($vma), -lma=>hex($lma), -fileoff=>hex($fileoff),
39 for my $k (sort {$section{$a}{-idx} <=> $section{$b}{-idx}} keys %section) {
40 if ($strip && $k =~ /\.(?:stab|debug)/o) {
41 push(@objcopy, '-R', $k);
45 $vma = $section{$k}{-vma};
47 if ($vma != $section{$k}{-vma}) {
48 my $newvma = align($vma, $section{$k}{-algn});
49 if ($newvma != $vma) {
50 printf STDERR "$0: ERROR $k VMA 0x%08x != 0x%08x\n", $vma, $newvma;
53 push(@objcopy, '--change-section-address', sprintf "$k=0x%08x", $vma);
55 $vma = align($vma + $section{$k}{-size}, $section{$k}{-algn});
58 warn "$0: ERROR final VMA (" . sprintf("0x%08x", $vma) . ") not on 64K boundary\n" if $vma != align($vma, 64 * 1024);
59 push(@objcopy, $dll, @ARGV);
63 my $align = $_[1] - 1;
64 return ($n + $align) & ~$align;
71 exec @_ or die "$0: couldn't exec $_[0] - $!\n";
73 system @_ and die "$0: couldn't exec $_[0] - $!\n";