[llvm] [z/OS] Add z/OS archive reading support (PR #187110)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Wed Apr 29 01:07:16 PDT 2026
================
@@ -1448,3 +1602,73 @@ BigArchive::BigArchive(MemoryBufferRef Source, Error &Err)
setFirstRegular(*I);
Err = Error::success();
}
+
+ZOSArchive::ZOSArchive(MemoryBufferRef Source, Error &Err)
+ : Archive(Source, Err) {
+ ErrorAsOutParameter ErrAsOutParam(&Err);
+
+ // Get the special members.
+ child_iterator I = child_begin(Err, false);
+ if (Err)
+ return;
+ child_iterator E = child_end();
+
+ // See if this is a valid empty archive and if so return.
+ if (I == E) {
+ Err = Error::success();
+ return;
+ }
+ const Child *C = &*I;
+
+ Expected<StringRef> NameOrErr = C->getRawName();
+ if (!NameOrErr) {
+ Err = NameOrErr.takeError();
+ return;
+ }
+ StringRef Name = NameOrErr.get();
+
+ if (Name == "__.SYMDEF") {
+ Expected<StringRef> BufOrErr = C->getBuffer();
+ if (!BufOrErr) {
+ Err = BufOrErr.takeError();
+ return;
+ }
+
+ // Copy symbol table converting embedded EBCDIC names to ASCII.
+ StringRef EbcdicSymbolTable = BufOrErr.get();
+ if (EbcdicSymbolTable.size() < sizeof(uint32_t)) {
+ Err = malformedError(
+ "z/OS symbol table is too small to read the symbol count");
+ return;
+ }
+ uint64_t EbcdicSymbolCount = read32be(EbcdicSymbolTable.data());
+ uint64_t OffsetToEbcdicNames =
+ sizeof(uint32_t) + (EbcdicSymbolCount * (sizeof(uint64_t)));
+ if (OffsetToEbcdicNames > EbcdicSymbolTable.size()) {
+ Err = malformedError("z/OS symbol table count exceeds buffer size");
----------------
jh7370 wrote:
I'd include both the offset and buffer size.
Also, technically, it's not the count that exceeds the buffer size, but rather the offset, since the count isn't the size of the thing, it's just a factor in the calculation, so I'd say "z/OS symbol table names offset exceeds buffer size" or something like that.
https://github.com/llvm/llvm-project/pull/187110
More information about the llvm-commits
mailing list