[Prev][Next][Index][Thread]

Re: fopen()




>         -loskit_c ../../lib/crtn.o
> mycode.o: In function `inicializar':
> mycode.o(.text+0x62a): undefined reference to `fs_init'
> ../../lib/liboskit_c.a(getchar.o): In function `getchar':
> getchar.o(.text+0x4): undefined reference to `console_getchar'
> ../../lib/liboskit_c.a(printf.o): In function `flush':
> printf.o(.text+0xf): undefined reference to `console_putbytes'
> ../../lib/liboskit_c.a(putchar.o): In function `putchar':
> putchar.o(.text+0x7): undefined reference to `console_putchar'
> make: *** [linux_fs_com] Error 1

The console functions come from libkern so you ought to compile with
-loskit_kern.  

To find the other functions, you could do something tedious like
reading the documentation but it's much easier to use perl scripts and
nm.  The attached scripts are, essentially, cleaned up versions of nm
which list the undefined symbols and the defined symbols in a .o or .a
file.  The really useful one is summarise which groups names according
to prefixes which you provide.  A typical use is:

   exports liboskit_kern.a | summarise pdir_ oskit_ pic_ i16_bios_ i16_ phys_ intr_ mem_ gdb_ console_ com_ dos_ cpu_ base_critical_ base_ anno_ direct_cons_

Whose output includes lines like:

        pic_{disable_irq,enable_irq,init,set_master,set_slave,test_irq}


Alastair



$ cat ~/bin/exports 
#! /usr/local/bin/perl 

#$nm = "/n/thistle/z/reid/ARM-ELF/install/bin/arm-foo-linux-gnuelf-nm";
$nm = "nm";

foreach $f (@ARGV) {
    ($IN,$OUT) = &typeof($f);
    $IN = &diff($IN,$OUT);

# Filter that strips internal symbols out
#
#     $IN  = &zap($IN, "^FDEV_LINUX_");
#     $OUT = &zap($OUT,"^FDEV_LINUX_");
# 
#     $IN  = &zap($IN, "^OSKIT_LINUX_");
#     $OUT = &zap($OUT,"^OSKIT_LINUX_");
# 
#     $IN  = &zap($IN, "_iid\$");

    print "\t", join("\n\t",sort(keys %$OUT)),"\n";
}

exit 0;

sub typeof {
    local ($filename) = @_;
    local (%IMPORTS,%EXPORTS);
    local ($x);
    open(FILE, "$nm -pa $filename |") || die "Can't find $filename\n";
    while (<FILE>) {
        @fields = split;

        if ($fields[0] =~ /[U]/) { 
            $IMPORTS{$fields[1]} = 1;
        } elsif ($fields[1] =~ /[ABCDGIRSTW]/) { 
            $EXPORTS{$fields[2]} = 1;
        }
    }
    return \(%IMPORTS,%EXPORTS);
#   close <FILE>;
}

sub diff {
    local ($X,$Y) = @_;
    local ($x,%r);
    foreach $x (keys %$X) {
        $r{$x} = 1 unless exists $$Y{$x};
    }
    return \%r;
}

sub zap {
    local ($X,$patt) = @_;
    local ($x,%r);
    foreach $x (keys %$X) {
        $r{$x} = 1 unless $x =~ /$patt/;
    }
    return \%r;
}

$ cat ~/bin/imports 
#! /usr/local/bin/perl 

#$nm = "/n/thistle/z/reid/ARM-ELF/install/bin/arm-foo-linux-gnuelf-nm";
$nm = "nm";

foreach $f (@ARGV) {
    ($IN,$OUT) = &typeof($f);
    $IN = &diff($IN,$OUT);

# Filter that strips internal symbols out
#
#     $IN  = &zap($IN, "^FDEV_LINUX_");
#     $OUT = &zap($OUT,"^FDEV_LINUX_");
# 
#     $IN  = &zap($IN, "^OSKIT_LINUX_");
#     $OUT = &zap($OUT,"^OSKIT_LINUX_");
# 
#     $IN  = &zap($IN, "_iid\$");

    print "\t",join("\n\t",sort(keys %$IN)), "\n";
}

exit 0;

sub typeof {
    local ($filename) = @_;
    local (%IMPORTS,%EXPORTS);
    local ($x);
    open(FILE, "$nm -pa $filename |") || die "Can't find $filename\n";
    while (<FILE>) {
        @fields = split;

        if ($fields[0] =~ /[U]/) { 
            $IMPORTS{$fields[1]} = 1;
        }
        if ($fields[1] =~ /[ABCDGIRSTW]/) { 
            $EXPORTS{$fields[2]} = 1;
        }
    }
    return \(%IMPORTS,%EXPORTS);
#   close <FILE>;
}

sub diff {
    local ($X,$Y) = @_;
    local ($x,%r);
    foreach $x (keys %$X) {
        $r{$x} = 1 unless exists $$Y{$x};
    }
    return \%r;
}

sub zap {
    local ($X,$patt) = @_;
    local ($x,%r);
    foreach $x (keys %$X) {
        $r{$x} = 1 unless $x =~ /$patt/;
    }
    return \%r;
}

cat ~/bin/summarise
#! /usr/local/bin/perl 

foreach $prefix (@ARGV) {
    @entries{$prefix} = [];
}

LINE: while (<STDIN>) {
    foreach $prefix (@ARGV) {
        if (/^(\s*)$prefix(\w*)/) {
            $foo = $entries{$prefix};
            push(@$foo,$2);
            $indent = $1;
            next LINE;
        }
    }
    print;
}

foreach $prefix (@ARGV) {
    $foo = $entries{$prefix};
    print "$indent$prefix\{", join(",",@$foo), "}\n";
}



References: