From 89e25d36aea7cfdf1c1b349dcb4109af2952549f Mon Sep 17 00:00:00 2001 From: Jiri Malak Date: Tue, 4 Jun 2024 12:34:32 +0200 Subject: [PATCH] nwlib: cleanup code to handle arch_header transparent way --- bld/nwlib/c/convert.c | 8 ++++---- bld/nwlib/c/implib.c | 25 +++++++++++++++++++------ bld/nwlib/c/proclib.c | 2 +- bld/nwlib/c/symtable.c | 8 +++++++- bld/nwlib/c/wlibutil.c | 2 +- bld/nwlib/h/convert.h | 4 ++-- bld/nwlib/h/wlibutil.h | 2 +- 7 files changed, 35 insertions(+), 16 deletions(-) diff --git a/bld/nwlib/c/convert.c b/bld/nwlib/c/convert.c index 112c8973c5..161a40301d 100644 --- a/bld/nwlib/c/convert.c +++ b/bld/nwlib/c/convert.c @@ -81,8 +81,8 @@ static size_t ARstrlen( const char * str ) return( c - str ); } -char *GetARName( libfile io, ar_header *header, arch_dict *dict ) -/***************************************************************/ +char *GetARName( libfile io, const ar_header *header, arch_dict *dict ) +/*********************************************************************/ { char buffer[AR_NAME_LEN + 1]; char *buf; @@ -147,7 +147,7 @@ static void GetARValue( const char *element, ar_len len, char delimiter, char *b buffer[len] = '\0'; } -void GetARHeaderValues( ar_header *header, arch_header * arch ) +void GetARHeaderValues( const ar_header *header, arch_header *arch ) { arch->date = GetARNumeric( header->date, AR_DATE_LEN ); arch->uid = GetARNumeric( header->uid, AR_UID_LEN ); @@ -156,7 +156,7 @@ void GetARHeaderValues( ar_header *header, arch_header * arch ) arch->size = GetARNumeric( header->size, AR_SIZE_LEN ); } -static void PutARPadding( char * element, ar_len current_len, ar_len desired_len ) +static void PutARPadding( char *element, ar_len current_len, ar_len desired_len ) { ar_len loop; diff --git a/bld/nwlib/c/implib.c b/bld/nwlib/c/implib.c index fe8028a94f..9236ddbcbd 100644 --- a/bld/nwlib/c/implib.c +++ b/bld/nwlib/c/implib.c @@ -181,9 +181,17 @@ static bool elfAddImport( libfile io, long header_offset, const arch_header *arc string_sec = ORLSecGetStringTable( sym_sec ); ORLSecGetContents( string_sec, (unsigned_8 **)&strings ); - tmp_arch.ffname = arch->name; - dllName.name = tmp_arch.name = dll_name = MemDupStr( TrimPath( arch->name ) ); + 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.libtype = arch->libtype; + + dllName.name = dll_name = MemDupStr( TrimPath( arch->name ) ); dllName.len = strlen( dllName.name ); + tmp_arch.name = dll_name; + tmp_arch.ffname = NULL; ElfMKImport( &tmp_arch, ELF, export_size, &dllName, strings, export_table, sym_table, processor ); @@ -421,11 +429,16 @@ static void peAddImport( libfile io, long header_offset, const arch_header *arch ord_table = (Coff32_EOrd *)(edata + export_header->OrdTableRVA - export_base.u._32[I64LO32] + adjust); ordinal_base = export_header->ordBase; - 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; + 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.libtype = arch->libtype; + + dllName.name = tmp_arch.name = edata + export_header->nameRVA - export_base.u._32[I64LO32] + adjust; dllName.len = strlen( dllName.name ); + tmp_arch.ffname = NULL; if( coff_obj ) { coffAddImportOverhead( &tmp_arch, &dllName, processor ); diff --git a/bld/nwlib/c/proclib.c b/bld/nwlib/c/proclib.c index b05bf583b0..60a12b6b1a 100644 --- a/bld/nwlib/c/proclib.c +++ b/bld/nwlib/c/proclib.c @@ -201,7 +201,7 @@ static void ProcessLibOrObj( const char *filename, objproc obj, libwalk_fn *proc } else { LibClose( io ); } -// FreeNewArch( &arch ); temporary fix until AddImport processing will be fixed + FreeNewArch( &arch ); } static void WalkInputLib( void ) diff --git a/bld/nwlib/c/symtable.c b/bld/nwlib/c/symtable.c index c96529e46e..7bf00d35aa 100644 --- a/bld/nwlib/c/symtable.c +++ b/bld/nwlib/c/symtable.c @@ -218,12 +218,17 @@ static sym_file *NewSymFile( const arch_header *arch, file_type obj_type ) sfile = MemAlloc( sizeof( sym_file ) ); sfile->obj_type = obj_type; - sfile->arch = *arch; sfile->first = NULL; sfile->next = NULL; sfile->impsym = NULL; sfile->inlib_offset = 0; sfile->full_name = MemDupStr( arch->name ); + sfile->arch.date = arch->date; + sfile->arch.uid = arch->uid; + sfile->arch.gid = arch->gid; + sfile->arch.mode = arch->mode; + sfile->arch.size = arch->size; + sfile->arch.libtype = arch->libtype; if( Options.trim_path ) { sfile->arch.name = MemDupStr( TrimPath( arch->name ) ); } else { @@ -234,6 +239,7 @@ static sym_file *NewSymFile( const arch_header *arch, file_type obj_type ) sfile->arch.ffname = MemDupStr( arch->ffname ); sfile->ffname_length = strlen( sfile->arch.ffname ); } else { + sfile->arch.ffname = NULL; sfile->ffname_length = 0; } *(FileTable.add_to) = sfile; diff --git a/bld/nwlib/c/wlibutil.c b/bld/nwlib/c/wlibutil.c index cb18e968c8..8594f79b77 100644 --- a/bld/nwlib/c/wlibutil.c +++ b/bld/nwlib/c/wlibutil.c @@ -104,7 +104,7 @@ libfile NewArchLibOpen( arch_header *arch, const char *filename ) return( LibOpen( filename, LIBOPEN_READ ) ); } -void FreeNewArch( arch_header *arch ) +void FreeNewArch( const arch_header *arch ) { MemFree( arch->name ); } diff --git a/bld/nwlib/h/convert.h b/bld/nwlib/h/convert.h index 3f4aeeba22..a7f2d228bb 100644 --- a/bld/nwlib/h/convert.h +++ b/bld/nwlib/h/convert.h @@ -31,7 +31,7 @@ ****************************************************************************/ -extern char *GetARName( libfile io, ar_header *header, arch_dict *dict ); +extern char *GetARName( libfile io, const ar_header *header, arch_dict *dict ); extern char *GetFFName( arch_dict *dict ); -extern void GetARHeaderValues( ar_header *header, arch_header *arch ); +extern void GetARHeaderValues( const ar_header *header, arch_header *arch ); extern void CreateARHeader( ar_header *ar, const arch_header *arch ); diff --git a/bld/nwlib/h/wlibutil.h b/bld/nwlib/h/wlibutil.h index a1793b159d..1768914f8b 100644 --- a/bld/nwlib/h/wlibutil.h +++ b/bld/nwlib/h/wlibutil.h @@ -52,7 +52,7 @@ extern bool IsSameModuleCase( const char *a, const char *b, int cmp_mode ); extern int SymbolNameCmp( const char *s1, const char *s2); extern bool IsExt( const char *a, const char *b ); extern libfile NewArchLibOpen( arch_header *arch, const char *filename ); -extern void FreeNewArch( arch_header *arch ); +extern void FreeNewArch( const arch_header *arch ); extern void DefaultExtension( char *name, const char *def_ext ); extern char *TrimPath( const char * ); extern void TrimPathInPlace( char * );