[llvm] [z/OS] Add z/OS archive reading support (PR #187110)
James Henderson via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 13 08:59:39 PDT 2026
================
@@ -1448,3 +1594,72 @@ 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") {
+ // We know that the symbol table is not an external file, but we still must
+ // check any Expected<> return value.
+ Expected<StringRef> BufOrErr = C->getBuffer();
+ if (!BufOrErr) {
+ Err = BufOrErr.takeError();
+ return;
+ }
+
+ // Copy symbol table converting embedded EBCDIC names to ASCII.
+ StringRef ESymbolTable = BufOrErr.get();
+ uint32_t ESymbolCount = read32be(ESymbolTable.data());
+ uint32_t OffsetToENames =
+ sizeof(uint32_t) + (ESymbolCount * (sizeof(uint64_t)));
+ uint32_t ENamesSize = (uint32_t)ESymbolTable.size() - OffsetToENames;
+ const char *ENamesPtr = (const char *)ESymbolTable.data() + OffsetToENames;
----------------
jh7370 wrote:
Coding standards say that C-style cast here is inappropriate. You should only use them for numeric casts.
https://github.com/llvm/llvm-project/pull/187110
More information about the llvm-commits
mailing list