[llvm-commits] Fix for ArchiveReader

Joe Abbey joe.abbey at gmail.com
Fri Mar 4 07:26:40 PST 2011


Not all archive files have a symbol table in front of it (which would
make firstFileOffset non-zero). In the case where an archive file, has
firstFirstOffset != 0, wrong offsets saved to the 'modules' map would
not always lead to linking failures because when a lookup fails, a
module is loaded
(but this time correctly) again via some other code in
ArchiveReader.cpp. So the problem can be masked because of that.

The root cause of the problem is a defect in ArchiveReader.cpp, inside
Archive::findModulesDefiningSymbols(). In particular, the code below

          // Insert the Module and the ArchiveMember into the table of
          // modules.
          modules.insert(std::make_pair(offset, std::make_pair(M, mbr)));

should be corrected as follows:

          // Insert the Module and the ArchiveMember into the table of
          // modules.
          modules.insert(std::make_pair(offset +
firstFileOffset,std::make_pair(M, mbr)));

The defect is the 'offset' value saved to the 'modules' map. The
'modules' map should store the physical file offset of the loaded
module (which is "offset + firstFileOffset", instead of the "offset"),
the distance of the loaded module member from the first member in the
archive file.

Cheers,

Joe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ArchiveReader.patch
Type: application/octet-stream
Size: 567 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20110304/5645e2ac/attachment.obj>


More information about the llvm-commits mailing list