From 63fb6999c644810ec40527aeba5edfe939117272 Mon Sep 17 00:00:00 2001 From: Jiri Malak Date: Tue, 4 Jun 2024 12:15:51 +0200 Subject: [PATCH] nwlib: use const pointer to arch_header where possible --- bld/nwlib/c/convert.c | 2 +- bld/nwlib/c/implib.c | 38 ++++++++++++++++-------------- bld/nwlib/c/libwalk.c | 53 +++++++++++++++++++++++------------------- bld/nwlib/c/proclib.c | 12 +++++----- bld/nwlib/c/symtable.c | 22 +++++++++--------- bld/nwlib/c/wlibutil.c | 2 +- bld/nwlib/h/convert.h | 6 ++--- bld/nwlib/h/filetab.h | 4 ++-- bld/nwlib/h/implib.h | 8 +++---- bld/nwlib/h/libwalk.h | 6 ++--- bld/nwlib/h/wlibutil.h | 2 +- 11 files changed, 81 insertions(+), 74 deletions(-) diff --git a/bld/nwlib/c/convert.c b/bld/nwlib/c/convert.c index ecc060b869..112c8973c5 100644 --- a/bld/nwlib/c/convert.c +++ b/bld/nwlib/c/convert.c @@ -203,7 +203,7 @@ static void PutARValueMode( char *element, uint_32 value, ar_len desired_len ) } } -void CreateARHeader( ar_header *ar, arch_header * arch ) +void CreateARHeader( ar_header *ar, const arch_header *arch ) { PutARName( ar->name, arch->name ); PutARValue( ar->date, arch->date, AR_DATE_LEN ); diff --git a/bld/nwlib/c/implib.c b/bld/nwlib/c/implib.c index 613e4af039..fe8028a94f 100644 --- a/bld/nwlib/c/implib.c +++ b/bld/nwlib/c/implib.c @@ -128,7 +128,7 @@ static orl_sec_handle FindSec( obj_file *ofile, const char *name ) return( found_sec_handle ); } -static bool elfAddImport( libfile io, long header_offset, arch_header *arch ) +static bool elfAddImport( libfile io, long header_offset, const arch_header *arch ) { obj_file *ofile; orl_sec_handle sym_sec; @@ -143,6 +143,7 @@ static bool elfAddImport( libfile io, long header_offset, arch_header *arch ) name_len dllName; Elf32_Word ElfMagic; char *dll_name; + arch_header tmp_arch; LibSeek( io, header_offset, SEEK_SET ); if( LibRead( io, &ElfMagic, sizeof( ElfMagic ) ) != sizeof( ElfMagic ) ) { @@ -180,21 +181,20 @@ static bool elfAddImport( libfile io, long header_offset, arch_header *arch ) string_sec = ORLSecGetStringTable( sym_sec ); ORLSecGetContents( string_sec, (unsigned_8 **)&strings ); - arch->ffname = arch->name; - dllName.name = arch->name = dll_name = MemDupStr( TrimPath( arch->name ) ); + tmp_arch.ffname = arch->name; + dllName.name = tmp_arch.name = dll_name = MemDupStr( TrimPath( arch->name ) ); dllName.len = strlen( dllName.name ); - ElfMKImport( arch, ELF, export_size, &dllName, strings, export_table, sym_table, processor ); + ElfMKImport( &tmp_arch, ELF, export_size, &dllName, strings, export_table, sym_table, processor ); MemFree( dll_name ); - arch->name = arch->ffname; CloseORLObjFile( ofile ); MemFree( ofile ); return( true ); } -static void importOs2Table( libfile io, arch_header *arch, name_len *dllName, bool coff_obj, importType type, unsigned length ) +static void importOs2Table( libfile io, const arch_header *arch, name_len *dllName, bool coff_obj, importType type, unsigned length ) { unsigned_16 ordinal; char sym_name[256]; /* maximum name len is 255 characters */ @@ -229,7 +229,7 @@ static void importOs2Table( libfile io, arch_header *arch, name_len *dllName, bo } } -static void os2AddImport( libfile io, long header_offset, arch_header *arch ) +static void os2AddImport( libfile io, long header_offset, const arch_header *arch ) { os2_exe_header os2_header; char dll_name[256]; /* maximum name len is 255 characters */ @@ -270,7 +270,7 @@ static void AddSym2( name_len *n1, const char *n2, symbol_strength strength, uns MemFree( sym_name ); } -static void coffAddImportOverhead( arch_header *arch, name_len *dllName, processor_type processor ) +static void coffAddImportOverhead( const arch_header *arch, name_len *dllName, processor_type processor ) { char *buffer; char *mod_name; @@ -290,7 +290,7 @@ static void coffAddImportOverhead( arch_header *arch, name_len *dllName, process MemFree( mod_name ); } -static void os2FlatAddImport( libfile io, long header_offset, arch_header *arch ) +static void os2FlatAddImport( libfile io, long header_offset, const arch_header *arch ) { os2_flat_header os2_header; char dll_name[256]; /* maximum name len is 255 characters */ @@ -317,7 +317,7 @@ static void os2FlatAddImport( libfile io, long header_offset, arch_header *arch } } -static bool nlmAddImport( libfile io, long header_offset, arch_header *arch ) +static bool nlmAddImport( libfile io, long header_offset, const arch_header *arch ) { nlm_header nlm; char dll_name[256]; /* maximum name len is 255 characters */ @@ -347,7 +347,7 @@ static bool nlmAddImport( libfile io, long header_offset, arch_header *arch ) return( true ); } -static void peAddImport( libfile io, long header_offset, arch_header *arch ) +static void peAddImport( libfile io, long header_offset, const arch_header *arch ) { obj_file *ofile; orl_sec_handle export_sec; @@ -364,6 +364,7 @@ static void peAddImport( libfile io, long header_offset, arch_header *arch ) importType type; bool coff_obj; long adjust; + arch_header tmp_arch; LibSeek( io, header_offset, SEEK_SET ); if( Options.libtype == WL_LTYPE_MLIB ) { @@ -420,22 +421,23 @@ static void peAddImport( libfile io, long header_offset, arch_header *arch ) ord_table = (Coff32_EOrd *)(edata + export_header->OrdTableRVA - export_base.u._32[I64LO32] + adjust); ordinal_base = export_header->ordBase; - arch->name = edata + export_header->nameRVA - export_base.u._32[I64LO32] + adjust; - arch->ffname = NULL; - dllName.name = arch->name; + tmp_arch = *arch; + tmp_arch.name = edata + export_header->nameRVA - export_base.u._32[I64LO32] + adjust; + tmp_arch.ffname = NULL; + dllName.name = tmp_arch.name; dllName.len = strlen( dllName.name ); if( coff_obj ) { - coffAddImportOverhead( arch, &dllName, processor ); + coffAddImportOverhead( &tmp_arch, &dllName, processor ); } for( i = 0; i < export_header->numNamePointer; i++ ) { sym_name = &(edata[name_table[i] - export_base.u._32[I64LO32] + adjust]); if( coff_obj ) { - CoffMKImport( arch, ORDINAL, ord_table[i] + ordinal_base, &dllName, sym_name, NULL, processor ); + CoffMKImport( &tmp_arch, ORDINAL, ord_table[i] + ordinal_base, &dllName, sym_name, NULL, processor ); AddSym2( &str_coff_imp_prefix, sym_name, SYM_WEAK, 0 ); } else { type = Options.r_ordinal ? ORDINAL : NAMED; - OmfMKImport( arch, type, ord_table[i] + ordinal_base, &dllName, sym_name, NULL, WL_PROC_X86 ); + OmfMKImport( &tmp_arch, type, ord_table[i] + ordinal_base, &dllName, sym_name, NULL, WL_PROC_X86 ); // AddSym2( &str_coff_imp_prefix, sym_name, SYM_WEAK, 0 ); } if( processor == WL_PROC_PPC ) { @@ -1049,7 +1051,7 @@ void ElfWriteImport( libfile io, sym_file *sfile ) } } -bool AddImport( libfile io, arch_header *arch ) +bool AddImport( libfile io, const arch_header *arch ) { unsigned_32 ne_header_off; long header_offset; diff --git a/bld/nwlib/c/libwalk.c b/bld/nwlib/c/libwalk.c index ab8cce3e9c..fdd44ab201 100644 --- a/bld/nwlib/c/libwalk.c +++ b/bld/nwlib/c/libwalk.c @@ -39,15 +39,15 @@ #include "clibext.h" -static void AllocFNameTab( libfile io, arch_header *arch, arch_dict *dict ) -/*************************************************************************/ +static void AllocFNameTab( libfile io, const arch_header *arch, arch_dict *dict ) +/*******************************************************************************/ { MemFree( dict->fnametab ); GetFileContents( io, arch, &dict->fnametab ); } -static void AllocFFNameTab( libfile io, arch_header *arch, arch_dict *dict ) -/**************************************************************************/ +static void AllocFFNameTab( libfile io, const arch_header *arch, arch_dict *dict ) +/********************************************************************************/ { MemFree( dict->ffnametab ); GetFileContents( io, arch, &dict->ffnametab ); @@ -56,14 +56,14 @@ static void AllocFFNameTab( libfile io, arch_header *arch, arch_dict *dict ) } -void LibWalk( libfile io, arch_header *arch, libwalk_fn *rtn ) -/************************************************************/ +void LibWalk( libfile io, const arch_header *arch, libwalk_fn *rtn ) +/******************************************************************/ { long pos; - char *oldname; + arch_header tmp_arch; - oldname = arch->name; - if( arch->libtype == WL_LTYPE_OMF ) { + tmp_arch.libtype = arch->libtype; + if( tmp_arch.libtype == WL_LTYPE_OMF ) { unsigned_16 pagelen; char buff[MAX_IMPORT_STRING]; unsigned_8 rec_type; @@ -82,6 +82,13 @@ void LibWalk( libfile io, arch_header *arch, libwalk_fn *rtn ) } LibSeek( io, pos, SEEK_CUR ); pos = LibTell( io ); + tmp_arch.date = arch->date; + tmp_arch.uid = arch->uid; + tmp_arch.gid = arch->gid; + tmp_arch.mode = arch->mode; + tmp_arch.size = arch->size; + tmp_arch.ffname = NULL; + tmp_arch.name = buff; while( LibRead( io, &rec_type, sizeof( rec_type ) ) == sizeof( rec_type ) && ( rec_type == CMD_THEADR ) ) { if( LibRead( io, &rec_len, sizeof( rec_len ) ) != sizeof( rec_len ) ) BadLibrary( io ); @@ -90,9 +97,8 @@ void LibWalk( libfile io, arch_header *arch, libwalk_fn *rtn ) if( LibRead( io, buff, str_len ) != str_len ) BadLibrary( io ); buff[str_len] = '\0'; - arch->name = buff; LibSeek( io, pos, SEEK_SET ); - rtn( io, arch ); + rtn( io, &tmp_arch ); pos = LibTell( io ); pos = __ROUND_UP_SIZE( pos, pagelen ); LibSeek( io, pos, SEEK_SET ); @@ -113,7 +119,7 @@ void LibWalk( libfile io, arch_header *arch, libwalk_fn *rtn ) if( strncmp( ar.header_ident, AR_HEADER_IDENT, AR_HEADER_IDENT_LEN ) ) { BadLibrary( io ); } - GetARHeaderValues( &ar, arch ); + GetARHeaderValues( &ar, &tmp_arch ); pos = LibTell( io ); if( ar.name[0] == '/' && ar.name[1] == ' ' @@ -122,32 +128,31 @@ void LibWalk( libfile io, arch_header *arch, libwalk_fn *rtn ) /* dict_count++; if( dict_count == 2 ) { - error = readDict( arch ); + error = readDict( &tmp_arch ); } else { - error = MoveAheadFrom( arch ); - updateNewArchive( arch ); + error = MoveAheadFrom( &tmp_arch ); + updateNewArchive( &tmp_arch ); } */ } else if( ar.name[0] == '/' && ar.name[1] == '/' && ar.name[2] == ' ' ) { - AllocFNameTab( io, arch, &dict ); + AllocFNameTab( io, &tmp_arch, &dict ); } else if( ar.name[0] == '/' && ar.name[1] == '/' && ar.name[2] == '/' ) { - AllocFFNameTab( io, arch, &dict ); + AllocFFNameTab( io, &tmp_arch, &dict ); } else { - arch->name = GetARName( io, &ar, &dict ); - arch->ffname = GetFFName( &dict ); - rtn( io, arch ); - MemFree( arch->name ); - MemFree( arch->ffname ); + tmp_arch.name = GetARName( io, &ar, &dict ); + tmp_arch.ffname = GetFFName( &dict ); + rtn( io, &tmp_arch ); + MemFree( tmp_arch.name ); + MemFree( tmp_arch.ffname ); } - pos += __ROUND_UP_SIZE_EVEN( arch->size ); + pos += __ROUND_UP_SIZE_EVEN( tmp_arch.size ); LibSeek( io, pos, SEEK_SET ); } MemFree( dict.fnametab ); MemFree( dict.ffnametab ); } - arch->name = oldname; } diff --git a/bld/nwlib/c/proclib.c b/bld/nwlib/c/proclib.c index 9d65a9f92b..b05bf583b0 100644 --- a/bld/nwlib/c/proclib.c +++ b/bld/nwlib/c/proclib.c @@ -37,14 +37,14 @@ #include "clibext.h" -static void SkipObject( libfile io, arch_header *arch ) +static void SkipObject( libfile io, const arch_header *arch ) { if( arch->libtype == WL_LTYPE_OMF ) { OmfSkipObject( io ); } } -static void CopyObj( libfile src, libfile dst, arch_header *arch ) +static void CopyObj( libfile src, libfile dst, const arch_header *arch ) { if( arch->libtype == WL_LTYPE_OMF ) { OmfExtract( src, dst ); @@ -53,7 +53,7 @@ static void CopyObj( libfile src, libfile dst, arch_header *arch ) } } -static void ExtractObj( libfile src, const char *name, arch_header *arch, const char *newname ) +static void ExtractObj( libfile src, const char *name, const arch_header *arch, const char *newname ) { long pos; libfile dst; @@ -71,7 +71,7 @@ static void ExtractObj( libfile src, const char *name, arch_header *arch, const } } -static void ProcessOneObject( libfile io, arch_header *arch ) +static void ProcessOneObject( libfile io, const arch_header *arch ) { lib_cmd *cmd; bool deleted; @@ -115,12 +115,12 @@ static void ProcessOneObject( libfile io, arch_header *arch ) } } -static void AddOneObject( libfile io, arch_header *arch ) +static void AddOneObject( libfile io, const arch_header *arch ) { AddObjectSymbols( io, LibTell( io ), arch ); } -static void DelOneObject( libfile io, arch_header *arch ) +static void DelOneObject( libfile io, const arch_header *arch ) { RemoveObjectSymbols( arch ); SkipObject( io, arch ); diff --git a/bld/nwlib/c/symtable.c b/bld/nwlib/c/symtable.c index df54141e8a..c96529e46e 100644 --- a/bld/nwlib/c/symtable.c +++ b/bld/nwlib/c/symtable.c @@ -211,8 +211,8 @@ static void RemoveFromHashTable( sym_entry *sym ) } -static sym_file *NewSymFile( arch_header *arch, file_type obj_type ) -/******************************************************************/ +static sym_file *NewSymFile( const arch_header *arch, file_type obj_type ) +/************************************************************************/ { sym_file *sfile; @@ -251,8 +251,8 @@ static int CompSyms( const void *ap, const void *bp ) return( strcmp( a->name, b->name ) ); } -static void WriteFileHeader( libfile io, arch_header *arch ) -/**********************************************************/ +static void WriteFileHeader( libfile io, const arch_header *arch ) +/****************************************************************/ { ar_header ar; @@ -943,8 +943,8 @@ void DumpHashTable( void ) #endif /* DEVBUILD */ -bool RemoveObjectSymbols( arch_header *arch ) -/*******************************************/ +bool RemoveObjectSymbols( const arch_header *arch ) +/*************************************************/ { sym_file *sfile; sym_file *sfile_prev; @@ -983,8 +983,8 @@ bool RemoveObjectSymbols( arch_header *arch ) return( false ); } -void AddObjectSymbols( libfile io, long offset, arch_header *arch ) -/*****************************************************************/ +void AddObjectSymbols( libfile io, long offset, const arch_header *arch ) +/***********************************************************************/ { obj_file *ofile; file_type obj_type; @@ -1022,7 +1022,7 @@ void AddObjectSymbols( libfile io, long offset, arch_header *arch ) MemFree( ofile ); } -void OmfMKImport( arch_header *arch, importType type, +void OmfMKImport( const arch_header *arch, importType type, long ordinal, name_len *dllName, const char *symName, const char *exportedName, processor_type processor ) { @@ -1046,7 +1046,7 @@ void OmfMKImport( arch_header *arch, importType type, AddSym( symName, SYM_STRONG, 0 ); } -void CoffMKImport( arch_header *arch, importType type, +void CoffMKImport( const arch_header *arch, importType type, long ordinal, name_len *dllName, const char *symName, const char *exportedName, processor_type processor ) { @@ -1079,7 +1079,7 @@ void CoffMKImport( arch_header *arch, importType type, } } -void ElfMKImport( arch_header *arch, importType type, long export_size, +void ElfMKImport( const arch_header *arch, importType type, long export_size, name_len *dllName, const char *strings, Elf32_Export *export_table, Elf32_Sym *sym_table, processor_type processor ) { diff --git a/bld/nwlib/c/wlibutil.c b/bld/nwlib/c/wlibutil.c index 41fcc230e7..cb18e968c8 100644 --- a/bld/nwlib/c/wlibutil.c +++ b/bld/nwlib/c/wlibutil.c @@ -71,7 +71,7 @@ int SymbolNameCmp( const char *s1, const char *s2) } } -void GetFileContents( libfile io, arch_header *arch, char **contents ) +void GetFileContents( libfile io, const arch_header *arch, char **contents ) { size_t size; diff --git a/bld/nwlib/h/convert.h b/bld/nwlib/h/convert.h index 00e0d1e243..3f4aeeba22 100644 --- a/bld/nwlib/h/convert.h +++ b/bld/nwlib/h/convert.h @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2024-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -33,5 +33,5 @@ extern char *GetARName( libfile io, ar_header *header, arch_dict *dict ); extern char *GetFFName( arch_dict *dict ); -extern void GetARHeaderValues( ar_header *header, arch_header * arch ); -extern void CreateARHeader( ar_header *ar, arch_header * arch ); +extern void GetARHeaderValues( ar_header *header, arch_header *arch ); +extern void CreateARHeader( ar_header *ar, const arch_header *arch ); diff --git a/bld/nwlib/h/filetab.h b/bld/nwlib/h/filetab.h index 633d8e6c7e..12bf7dbc04 100644 --- a/bld/nwlib/h/filetab.h +++ b/bld/nwlib/h/filetab.h @@ -118,8 +118,8 @@ extern void FiniFileTab( void ); extern void ResetFileTab( void ); extern void CleanFileTab( void ); extern void ListContents( void ); -extern void AddObjectSymbols( libfile io, long offset, arch_header *arch ); -extern bool RemoveObjectSymbols( arch_header *arch ); +extern void AddObjectSymbols( libfile io, long offset, const arch_header *arch ); +extern bool RemoveObjectSymbols( const arch_header *arch ); extern void SymCalcNewOffsets( void ); extern void WriteFileTable( libfile io ); extern void WriteFileBody( libfile io, sym_file *sfile ); diff --git a/bld/nwlib/h/implib.h b/bld/nwlib/h/implib.h index f2858ea9ff..c6bd441cf9 100644 --- a/bld/nwlib/h/implib.h +++ b/bld/nwlib/h/implib.h @@ -65,10 +65,10 @@ typedef unsigned_16 Coff32_EOrd; extern unsigned char ElfBase[]; extern char ElfOSInfo[]; -extern bool AddImport( libfile io, arch_header *arch ); -extern void OmfMKImport( arch_header *, importType, long, name_len *, const char *, const char *, processor_type ); -extern void CoffMKImport( arch_header *, importType, long, name_len *, const char *, const char *, processor_type ); -extern void ElfMKImport( arch_header *, importType, long, name_len *, const char *, Elf32_Export *, Elf32_Sym *, processor_type ); +extern bool AddImport( libfile io, const arch_header *arch ); +extern void OmfMKImport( const arch_header *, importType, long, name_len *, const char *, const char *, processor_type ); +extern void CoffMKImport( const arch_header *, importType, long, name_len *, const char *, const char *, processor_type ); +extern void ElfMKImport( const arch_header *, importType, long, name_len *, const char *, Elf32_Export *, Elf32_Sym *, processor_type ); extern size_t CoffImportSize( import_sym *impsym ); extern size_t ElfImportSize( import_sym *impsym ); extern void CoffWriteImport( libfile, sym_file *, bool ); diff --git a/bld/nwlib/h/libwalk.h b/bld/nwlib/h/libwalk.h index 2ead906355..eda44ba3f7 100644 --- a/bld/nwlib/h/libwalk.h +++ b/bld/nwlib/h/libwalk.h @@ -2,7 +2,7 @@ * * Open Watcom Project * -* Copyright (c) 2024 The Open Watcom Contributors. All Rights Reserved. +* Copyright (c) 2024-2024 The Open Watcom Contributors. All Rights Reserved. * Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved. * * ======================================================================== @@ -31,6 +31,6 @@ ****************************************************************************/ -typedef void libwalk_fn( libfile io, arch_header *arch ); +typedef void libwalk_fn( libfile io, const arch_header *arch ); -extern void LibWalk( libfile io, arch_header *arch, libwalk_fn *rtn ); +extern void LibWalk( libfile io, const arch_header *arch, libwalk_fn *rtn ); diff --git a/bld/nwlib/h/wlibutil.h b/bld/nwlib/h/wlibutil.h index da2a6902fa..a1793b159d 100644 --- a/bld/nwlib/h/wlibutil.h +++ b/bld/nwlib/h/wlibutil.h @@ -42,7 +42,7 @@ WL_PROCS WL_FTYPES #undef WL_FTYPE -extern void GetFileContents( libfile io, arch_header *arch, char **contents ); +extern void GetFileContents( libfile io, const arch_header *arch, char **contents ); extern void Copy( libfile src, libfile dst, file_offset size ); extern char *MakeObjOutputName( const char *src, const char *new ); extern char *MakeListName( void );