next up previous Back to Operating Systems Home Page
Next: 1997 term messages Up: 1998 term messages Previous: A1: ERRATADLL,

Tutorial rescheduled

[ This message was sent out saturday night, but the EE Majordomo 
  list server sems to be broken, and it might have not been received
  by several students -- rebroadcasting, apologies to those
  who might receive multiple copies ... ]


Hello, everyone

A few replies to questions I have received on assignment 1

1. ERRATA/CORRIGE

There is a typo in the assignment 1 text distributed yesterday
(well, sort of, it's really a difference between the Irix version
 of the dld library, which I referred to, and the GNU one available 
 on the lab machines and under Linux).

In Part A, point 2:
where it says 
        "dynamically-loadable object files taskname.o"
read
        "dynamically-loadable object files taskname.so.1.0"

The online versions of the text (HTML and PS) have been corrected
accordingly.

The ".so" extension means "shared object" in unixish, and indicates a
file containing dynamically loadable object code (in microsoftish
you'd write .DLL and read "dynamical link library").  The actual
values of last two numbers (respectively, the major and minor version
number of the DLL) don't really matter for your assignment, but they
must be there, otherwise the dynamic loading won't work.  Choose yours
and be consistent in their usage.

2. DLL's

Judging from the emails I have received so far, quite a few of the
students who went through the assignment text (and/or the attached
man pages for dlopen(3)) got stuck on the mysterious expressions
"dynamically-loadable objects" and "dynamic library": now, WTH might
those beasts be?

if (you already know everything there's to know about doing
    them under UNIX) 
{
        Hit DELETE now ;-)
}
else if (you know what a library is, but have never rolled one under UNIX)
{ 
        Keep reading this message ;-)
}
else if (you have no clue about what an object library is) 
{
        Read the message entitled "Compiling problems" in the "1997
        term messages" section of the mailing list archive, available
        on the OS web page (follow the link "FAQ and previous messages
        that might interest you").

        if (you have read that message 
            && still haven't got a clue)
        {
                I am afraid you may not be exactly ready 
                for this course... :-(
        }
}

Static libraries (libXXX.a files) are easy. They are just the
concatenation of a bunch of relocatable objects (YYY.o files), plus an
index at the head.  Here's a quick recipe for cooking them
        1. Write your C sources and compile them as relocatable
           objects:
                % gcc -c wag.c the.c dog.c 
           this will produce the objects wag.o, the.o and dog.o.
        2. Archive them in a library file, using ar(1)
                % ar rcs libmovie.a wag.o the.o dog.o
           this will create the library libmovie.a and prepend
           the appropriate index. Read "man 1 ar" for more.
        3. Use their content in your programs by linking them
                % gcc cinema.c -o cinema -L/path/to/the/library -lmovie    
        
But for the assignment you need to roll dynamic libraries (i.e. files
with names like ZZZ.so.1.0). These are just a little bit harder, since
you have to archive them calling the linker through the compiler. Here's
the recipe:
        1. Same as above, but tell the compiler to generate "position
           independent" object code using the -fPIC option too:
                % gcc -c -fPIC wag.c the.c dog.c
        2. Link the .o files generated in step 1 into a shared object
           by calling the linker through the compiler, like thus:
                % gcc -shared -Wl,-soname,libmovie.so.1 
                  -o libmovie.so.1.0 wag.o the.o dog.o
           all in one shell command line. The commas after the -Wl
           option are important, do not type any spaces after
           them. Write only the first (major) version number after the
           "soname" option, and both the first and the second (minor)
           number after the -o option.
        2.1. If your DLL needs other libraries to work, pass 
           the appropriate -lxxx switches at the end of the above
           command line. For example, if dog.c uses the cos()
           function, put a -lm switch at the end, so to link the math
           library as well. 
        3. Normally, same as step 3 for the static case, EXCEPT....
        
EXCEPT... that in your (Assig. 1) case you don't want to link your
program (the task switcher) with the shared objects (the tasks) 
when the switcher is compiled, but rather when it is run. So?

        HINT 1
        ... So you just make a shared object as above for each of
            the tasks, and then use dlopen() inside the switcher ;-)

        HINT 2 (the revenge)
        ... and don't forget to link the dynamic linker routines
            when you compile the switcher ( -ldl )

3. FAQ FAQ FAQ

Other questions I received are really FAQ, and they are already
answered in the mailing list archive available on the OS web page.
See, for example, the answer from Q3 onward in the "Assig 2 FAQ"
message, in the "1997 term messages" section as well

Keep hacking
Franco



\ Franco Callari