ld error
Dear All,
I am working through 'Linux Assembly "Hello World" Tutorial, CS 200' by Bjorn Chambless. But I am unable to compile the program given in that. Kindly help me.
For your convenience I have included the assembly program at the end of this mail.
average.s is the relevant assembly program file.
$ as -a --gstabs -o average.o average.s
$ ld -m elf_i386 -static /usr/lib/crt1.o /usr/lib/crti.o -lc average.o
/usr/lib/crtn.o/usr/lib/libc.a(strtoll.o): In function `__strtoll_internal':/usr/src/bs/BUILD/glibc-2.2.2/stdlib/../sysdeps/generic/strtol.c:386: undefined reference to __udivdi3' /usr/src/bs/BUILD/glibc-2.2.2/stdlib/../sysdeps/generic/strtol.c:387: undefined reference to __umoddi3' /usr/lib/libc.a(strtoull.o): In function `__strtoull_internal':/usr/src/bs/BUILD/glibc-2.2.2/stdlib/../sysdeps/generic/strtol.c:386: undefined reference to __udivdi3' /usr/src/bs/BUILD/glibc-2.2.2/stdlib/../sysdeps/generic/strtol.c:387: undefined reference to __umoddi3'
$ cat average.s .data
.type hi_temp,@object
.size hi_temp,1
hi_temp:
.byte 0x92
.type lo_temp,@object
.size lo_temp,1
lo_temp:
.byte 0x52
.type av_temp,@object
.size av_temp,1
av_temp:
.byte 0.text
.align 4
.globl main
.type main,@function
main:
pushl %ebp
movl %esp,%ebp
movb hi_temp,%al
addb lo_temp,%al
movb $0,%ah
adcb $0,%ah
movb $2,%bl
idivb %bl
movb %al,av_temp
leave
ret $ as --version GNU assembler 2.10.91 Copyright 2001 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License. This program has absolutely no warranty. This assembler was configured for a target of `i386-redhat-linux'.
$ ld --version GNU ld 2.10.91 Copyright 2001 Free Software Foundation, Inc. This program is free software; you may redistribute it under the terms of the GNU General Public License. This program has absolutely no warranty. Supported emulations: elf_i386 i386linux elf_i386_glibc21
$ gcc --version 2.96
$ uname -a Linux wobble 2.4.16 #8 Tue May 14 14:15:58 IST 2002 i686 unknown
$ cat /etc/issue
Red Hat Linux release 7.1 (Seawolf)
Kernel 2.4.16 on an i686
Hope somebody will help me with this.
Thank you.
Cheers,
anna
Signature · 7 lines
(15) I will never employ any device with a digital countdown. If I find
that such a device is absolutely unavoidable, I will set it to
activate when the counter reaches 117 and the hero is just putting
his plan into operation. - Peter Anspach in "The Top 100 Things
I'd Do If I Ever Became An Evil Overlord"
http://www.eviloverlord.comHi,
Quoted 3 lines
I am working through 'Linux Assembly "Hello World" Tutorial, CS 200' by Bjorn Chambless. But I am unable to compile the program given in that. Kindly help me.
i suspect that exercise isn't a simple "hello world"-program. It seems to me as a nasty trap for lazy students :-))
The module "average" is a subroutine e.g. a "function" which should be linked to a given C-Program.
For my first step i'm looking for a readable tutorial to the "gas"-assembler.
Have you seen anything in the web ?
Thanks,
Alfred
Signature · 5 lines
Alfred Cleve Karbener Str. 7 61130 Nidderau-Heldenbergen Germany Phone +49-6187-901095
Quoted 11 lines
Date: Mon, 27 May 2002 20:27:52 +0200
From: [email protected] (Alfred Cleve)
Subj: Re: ld errorHi,
Quoted 3 lines
I am working through 'Linux Assembly "Hello World" Tutorial, CS 200' by Bjorn Chambless. But I am unable to compile the program given in that. Kindly help me.
Quoted 5 lines
i suspect that exercise isn't a simple "hello world"-program. It seems to me as a nasty trap for lazy students :-))
The module "average" is a subroutine e.g. a "function" which should be linked to a given C-Program.
I don't think so, because the given assembly program has a main function; and the tutorial has given a step by step procedure to produce the executable.
Inspite of my above statement, I am not very sure of the given assembly program being complete, basically because it doesn't work! But it does have a main function.
[ Added as an after-thought: Doesn't the function named 'main' have any special significance in assembly language programs? ]
(begin-quote)
/* segment registers set up by linked code */
/* beginning of text(code) segment */
.text
.align 4 /* set 4 double-word alignment */
.globl main /* make main global for linker */
.type main,@function /* declare main as a function */
main:
(definition of main snipped)
(end-quote)
If what you say is correct, then I don't think the tutorial serves its purpose. Already, I am pulling my hairs to understand what is going on, and now I have got to put up with the caveats that the author thought to be educational. (No offence meant to the author, its just my critique of the tutorial.)
Quoted 2 lines
For my first step i'm looking for a readable tutorial to the "gas"-assembler.
Simply start from http://www.linuxassembly.org
Cheers,
anna
Signature · 7 lines
(15) I will never employ any device with a digital countdown. If I find
that such a device is absolutely unavoidable, I will set it to
activate when the counter reaches 117 and the hero is just putting
his plan into operation. - Peter Anspach in "The Top 100 Things
I'd Do If I Ever Became An Evil Overlord"
http://www.eviloverlord.comQuoted 7 lines
I don't think so, because the given assembly program has a main function; and the tutorial has given a step by step procedure to produce the executable.
Inspite of my above statement, I am not very sure of the given assembly program being complete, basically because it doesn't work! But it does have a main function.
Instead of having to build the link line yourself, you could just let gcc do it for you. That is, instead of:
ld -m elf_i386 -static average.o /usr/lib/crtn.o /foo/bar/baz blahblahblah
use:
gcc -static average.o
b
No, "main" doesn't have any special significance in assembly and is NOT required. However, the assembler _does_ look for a procedure named "_start", but this also is not required because it will default to something else and just give you a warning about it if it's not included. BTW, I understand how you feel about pulling your hair out, but this is the best way to learn _any_ language. Also, all you really need to do to assemble and link a program is the following:
as -o hello.o hello
ld -o hello hello.o
All the other stuff is just extra. I usually assembly my programs with --gstabs so that I can debug them with gdb, but it's not necessary for the program to assemble. --gstabs is the same as the -g when compiling C programs.
Cheers,
Jeff Souza
Quoted 53 lines · G Anna
Quoted 10 lines
Date: Mon, 27 May 2002 20:27:52 +0200
From: [email protected] (Alfred Cleve)
Subj: Re: ld errorHi,
Quoted 3 lines
I am working through 'Linux Assembly "Hello World" Tutorial, CS 200' by Bjorn Chambless. But I am unable to compile the program given in that. Kindly help me.
Quoted 5 lines
i suspect that exercise isn't a simple "hello world"-program. It seems to me as a nasty trap for lazy students :-))
The module "average" is a subroutine e.g. a "function" which should be linked to a given C-Program.
I don't think so, because the given assembly program has a main function; and the tutorial has given a step by step procedure to produce the executable.
Inspite of my above statement, I am not very sure of the given assembly program being complete, basically because it doesn't work! But it does have a main function.
[ Added as an after-thought: Doesn't the function named 'main' have any special significance in assembly language programs? ]
(begin-quote)
/* segment registers set up by linked code */
/* beginning of text(code) segment */
.text
.align 4 /* set 4 double-word alignment */
.globl main /* make main global for linker */
.type main,@function /* declare main as a function */
main:
(definition of main snipped)(end-quote)
If what you say is correct, then I don't think the tutorial serves its purpose. Already, I am pulling my hairs to understand what is going on, and now I have got to put up with the caveats that the author thought to be educational. (No offence meant to the author, its just my critique of the tutorial.)
Quoted 2 lines
For my first step i'm looking for a readable tutorial to the "gas"-assembler.
Simply start from http://www.linuxassembly.org
Cheers,
anna
Quoted 11 lines · Brian Raiter
Quoted 7 lines
I don't think so, because the given assembly program has a main function; and the tutorial has given a step by step procedure to produce the executable.
Inspite of my above statement, I am not very sure of the given assembly program being complete, basically because it doesn't work! But it does have a main function.
Instead of having to build the link line yourself, you could just let gcc do it for you. That is, instead of:
Quoted 6 lines
ld -m
elf_i386-static average.o/usr/lib/crtn.o/foo/bar/baz
blahblahblahuse:
gcc -static average.o
I use gas for teaching assembly language. I have my students simply use
gcc average.o -o average
Then they can use C library functions to do I/O. For example, I have them use read() and write() to interact with the terminal. By restricting them to read/write one byte at a time, I can give several interesting assignments to help them learn how fundamental C programming constructs are implemented at the assembly language level. (Well, how they *could* be implemented; compilers sometimes do silly things.)
Quoted 7 lines
b
-
To unsubscribe from this list: send the line "unsubscribe linux-assembly" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
-------------------------------------------------------
Robert G. Plantz, PhD |
Professor of Computer Science | cs.sonoma.edu/~bob
Sonoma State University | [email protected]
1801 E. Cotati Ave. | ph: 707.664.2806
Rohnert Park, CA 94928 | fax: 707.664.3012