Skip to content

Regression(https://reviews.llvm.org/D143540): llvm-lib writes broken .lib files when output is > 4 GiB #160112

@nico

Description

@nico

Reduced repro (file names > 15 characters so that the string table is used):

% cat foo34567890123456789.cc 
void foo() {}
% cat bar34567890123456789.cc 
void bar() {}

Compile them and make a .lib, using SYM64_THRESHOLD to force switch to 64-bit mode without needing many large obj files:

% out/gn/bin/clang-cl /c foo34567890123456789.cc                                                                                 
% out/gn/bin/clang-cl /c bar34567890123456789.cc                                                             
% SYM64_THRESHOLD=800 out/gn/bin/lld-link /lib /out:foo.lib foo34567890123456789.obj bar34567890123456789.obj

Use it:

% cat main.cc   
void foo();
void bar();
int main() {
  foo();
  bar();
}

% out/gn/bin/clang-cl /c main.cc

% out/gn/bin/lld-link /winsysroot:$HOME/src/chrome/src/third_party/depot_tools/win_toolchain/vs_files/e4305f407e main.obj foo.lib
lld-link: error: could not get child name for archive foo.lib while loading symbol void __cdecl foo(void): truncated or malformed archive (string table at long name offset 25 not terminated)

The problem is that writeArchiveToStream in llvm/lib/Object/ArchiveWriter.cpp dynamically switches Kind to object::Archive::K_GNU64 if the output becomes large enough to require 64-bit offsets, but after https://reviews.llvm.org/D143540 / 4fcbf38, several places in ArchiveWriter.cpp check Kind and make binding decisions based on it before Kind may change.

Options:

  1. Short-term, revert the change to LibDriver.cpp to always use K_GNU to unbreak things
  2. In ArchiveWriter, maybe do a first pass to figure out the final Kind, and then don't change Kind while writing in a second, actually-writing pass

@cjacek

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions