#! /usr/bin/perl -w

# Parse the output of `ld --verbose' to produce a linker script with
# a modified text address.

# Feel free to rewrite this in awk/shell/etc.
# Feel even freer to make it an `ld' option or show me how to achieve
# it through prescribed means.

$addr = shift;
while (<>) {
    last if /=========/;
}
if (! defined($_)) {
    die ("$0: ld --verbose output not in expected format.\n");
}
while (<>) {
    last if /=========/;
    if (s/(\.\s*=\s*)0x\w*(\s*\+\s*SIZEOF_HEADERS)/$1$addr$2/) {
	$found = 1;
    }
    print;
}
while (<>) {
    # ignore trailing junk
}
if (! $found) {
    die ("$0: Origin not found in default linker script.\n");
}
