Skip to content

Commit f1ab664

Browse files
committed
rustc_back: Only use archive member filenames
I've been working with some archives generated by MSVC's `lib.exe` tool lately, and it looks like the embedded name of the members in those archives sometimes have slahes in the name (e.g. `foo/bar/baz.obj`). Currently the compiler chokes on these paths as it assumes that each file in the archive is only the filename (which is what unix does). This commit interprets the name of each file in all archives as a path and then only uses the `file_name` portion of the path to extract the file to a separate location and then reassemble it back into a new archive later. Note that duplicate filenames are already handled, so this won't introduce any conflicts.
1 parent 7132092 commit f1ab664

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/librustc_back/archive.rs

+15
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,21 @@ impl<'a> ArchiveBuilder<'a> {
306306
if filename.contains(".SYMDEF") { continue }
307307
if skip(filename) { continue }
308308

309+
// Archives on unix systems typically do not have slashes in
310+
// filenames as the `ar` utility generally only uses the last
311+
// component of a path for the filename list in the archive. On
312+
// Windows, however, archives assembled with `lib.exe` will preserve
313+
// the full path to the file that was placed in the archive,
314+
// including path separators.
315+
//
316+
// The code below is munging paths so it'll go wrong pretty quickly
317+
// if there's some unexpected slashes in the filename, so here we
318+
// just chop off everything but the filename component. Note that
319+
// this can cause duplicate filenames, but that's also handled below
320+
// as well.
321+
let filename = Path::new(filename).file_name().unwrap()
322+
.to_str().unwrap();
323+
309324
// An archive can contain files of the same name multiple times, so
310325
// we need to be sure to not have them overwrite one another when we
311326
// extract them. Consequently we need to find a truly unique file

0 commit comments

Comments
 (0)