pete > courses > CS 315 Fall 26 > Assignment 6


Assignment 6

If any of this is unclear, please get in touch with me ASAP. There are definitely things in the course I want you to struggle with. I absolutely do NOT want you struggling with understanding my expectations.

In this assignment, you will implement the six functions from Assignment 2 using mmap(2) wherever possible. (Use the same function and struct names—and even the same header file.) The result will be a shared library, which will be linked at runtime with your test program.

You need not implement any buffering: mmap itself takes care of loading the data into memory as necessary (the precise mechanics will be discussed when we talk about virtual memory and/or you take Operating Systems).

New Mechanics

You might find these useful in this assignment.

New functions

Compiling a shared library

You compiled a shared library in Assignment 3, but that was a slightly special case because it was intended specifically for use with LD_PRELOAD. Compiling a "real" shared library requires some different steps.

First, you must compile the constituent source files using the -fPIC flag. Then, when you have compiled the source file into object code, use this command to make a shared library out of it (ie, this is the linking step):

$ gcc -shared -Wl,-soname,libmymmapio.so -o libmymmapio.so mymmapio.o

Linking with a shared library

Normally, the linker will look in a set of preconfigured directories to find libraries against which to link. The current directory (which is presumably where, eg, libmyio.so will reside) is not in this list. When linking, use the -L flag to tell gcc where else to look for libraries. Therefore, to compile foo.o into an executable named foo, and to link with libbar.so which is in the current directory ("."), use this command:

$ gcc -L. -lbar -o foo foo.o

Note that this will work even if the library has a version number attached to it. So if you want to link with libbar.so.4.3.2, you still use -lbar and it will find the correct file.

Running with a shared library (in a non-traditional location)

You linked to the library using the preceding command, and now you go to run it… but how does the program know where to find the library? The "-L." parameter during compilation doesn’t tell the program where to find the library when it’s actually being run. And, really, there’s no way it can: what if the library is moved? What if the program itself is moved and "." suddenly refers to a completely different directory?

As with compile-time linking, there are a preconfigured set of directories searched for libraries to be linked at runtime [1]. The LD_LIBRARY_PATH environment variable augments this list. Thus, to cause the runtime linker to look in the current directory (in addition to default directories) for libraries, run the program like so:

$ LD_LIBRARY_PATH=. ./foo

[1] For the curious, the list of directories searched is controlled by config files in /etc/ld.so.conf.d.

Behavioral requirements

You will produce a source file, test-myio.c, that contains a set of tests to verify the correctness of your I/O libraries. As discussed in class, one way to test whether your my* functions work correctly is to call the exact same sequence of non-my functions and compare the results. The key is going to be choosing the sequence of function calls that adequately test your code. You should probably use our discussion of basic blocks to guide your thought process in devising these tests.

I should be able to link this program against either of your I/O libraries to test them.

When run, the test program should print a short description of each test and whether or not it passed. Your tests should test all functionality of your libraries. If you would like to discuss your tests to make sure they are sufficient, I’m happy to do so.

Deliverable requirements

Lots of files:

Style requirements

Your code must exhibit:

Submission Process

Your submission files should be in a git repository on basin in this directory:

/home/<username>/<secret>/assignment6

Email me when you want feedback, with a description of the type of feedback you would like.

Last modified: