Add filename back into invalid lib test

This commit is contained in:
Dennis Korpel 2024-10-09 16:24:07 +02:00
parent 74e47d959a
commit 52524f1c34
8 changed files with 34 additions and 33 deletions

View file

@ -93,8 +93,8 @@ final class LibElf : Library
void corrupt(int reason)
{
eSink.error(loc, "corrupt ELF object module %.*s %d",
cast(int)module_name.length, module_name.ptr, reason);
eSink.error(Loc.initial, "corrupt ELF object `%.*s` module %.*s %d",
filename.fTuple.expand, module_name.fTuple.expand, reason);
}
int fromfile = 0;
@ -329,7 +329,7 @@ final class LibElf : Library
s = tab.lookup(name.ptr, name.length);
assert(s);
ElfObjSymbol* os = s.value;
eSink.error(loc, "multiple definition of %s: %s and %s: %s", om.name.ptr, name.ptr, os.om.name.ptr, os.name.ptr);
eSink.error(Loc.initial, "multiple definition of %s: %s and %s: %s", om.name.ptr, name.ptr, os.om.name.ptr, os.name.ptr);
}
}
else
@ -359,7 +359,7 @@ private:
this.addSymbol(om, name, pickAny);
}
scanElfObjModule(&addSymbol, om.base[0 .. om.length], om.name.ptr, loc, eSink);
scanElfObjModule(&addSymbol, om.base[0 .. om.length], om.name.ptr, filename, eSink);
}
/*****************************************************************************/

View file

@ -94,8 +94,8 @@ final class LibMach : Library
void corrupt(int reason)
{
eSink.error(loc, "corrupt Mach object module %.*s %d",
cast(int)module_name.length, module_name.ptr, reason);
eSink.error(Loc.initial, "corrupt Mach object `%.*s` module %.*s %d",
filename.fTuple.expand, module_name.fTuple.expand, reason);
}
int fromfile = 0;
@ -323,7 +323,7 @@ private:
this.addSymbol(om, name, pickAny);
}
scanMachObjModule(&addSymbol, om.base[0 .. om.length], om.name.ptr, loc, eSink);
scanMachObjModule(&addSymbol, om.base[0 .. om.length], om.name.ptr, filename, eSink);
}
/*****************************************************************************/

View file

@ -101,8 +101,8 @@ final class LibMSCoff : Library
void corrupt(int reason)
{
eSink.error(loc, "corrupt MS Coff object module %.*s %d",
cast(int)module_name.length, module_name.ptr, reason);
eSink.error(Loc.initial, "corrupt MS Coff object `%.*s` module %.*s %d",
filename.fTuple.expand, module_name.fTuple.expand, reason);
}
int fromfile = 0;
@ -400,7 +400,7 @@ private:
this.addSymbol(om, name, pickAny);
}
scanMSCoffObjModule(&addSymbol, om.base[0 .. om.length], om.name.ptr, loc, eSink);
scanMSCoffObjModule(&addSymbol, om.base[0 .. om.length], om.name.ptr, filename, eSink);
}
/*****************************************************************************/

View file

@ -67,5 +67,4 @@ class Library
public:
const(char)[] filename; /// the filename of the library
Loc loc; /// used for error printing
}

View file

@ -17,6 +17,7 @@ import core.checkedint;
import dmd.errorsink;
import dmd.location;
import dmd.root.string : fTuple;
nothrow:
@ -29,12 +30,12 @@ enum LOG = false;
* pAddSymbol = function to pass the names to
* base = array of contents of object module
* module_name = name of the object module (used for error messages)
* loc = location to use for error printing
* filename = object file name for error printing
* eSink = where the error messages go
*/
package(dmd.lib)
void scanElfObjModule(void delegate(const(char)[] name, int pickAny) nothrow pAddSymbol,
scope const ubyte[] base, const char* module_name, Loc loc, ErrorSink eSink)
scope const ubyte[] base, const char* module_name, const(char)[] filename, ErrorSink eSink)
{
static if (LOG)
{
@ -43,7 +44,7 @@ void scanElfObjModule(void delegate(const(char)[] name, int pickAny) nothrow pAd
void corrupt(int reason)
{
eSink.error(loc, "corrupt ELF object module `%s` %d", module_name, reason);
eSink.error(Loc.initial, "corrupt ELF object `%.*s` module `%s` %d", filename.fTuple.expand, module_name, reason);
}
if (base.length < Elf32_Ehdr.sizeof)
@ -54,16 +55,16 @@ void scanElfObjModule(void delegate(const(char)[] name, int pickAny) nothrow pAd
if (base[EI_VERSION] != EV_CURRENT)
{
return eSink.error(loc, "ELF object module `%s` has EI_VERSION = %d, should be %d",
return eSink.error(Loc.initial, "ELF object module `%s` has EI_VERSION = %d, should be %d",
module_name, base[EI_VERSION], EV_CURRENT);
}
if (base[EI_DATA] != ELFDATA2LSB)
{
return eSink.error(loc, "ELF object module `%s` is byte swapped and unsupported", module_name);
return eSink.error(Loc.initial, "ELF object module `%s` is byte swapped and unsupported", module_name);
}
if (base[EI_CLASS] != ELFCLASS32 && base[EI_CLASS] != ELFCLASS64)
{
return eSink.error(loc, "ELF object module `%s` is unrecognized class %d", module_name, base[EI_CLASS]);
return eSink.error(Loc.initial, "ELF object module `%s` is unrecognized class %d", module_name, base[EI_CLASS]);
}
void scanELF(uint model)() nothrow
@ -87,7 +88,7 @@ void scanElfObjModule(void delegate(const(char)[] name, int pickAny) nothrow pAd
const eh = cast(const(ElfXX_Ehdr)*) base.ptr;
if (eh.e_type != ET_REL)
return eSink.error(loc, "ELF object module `%s` is not relocatable", module_name);
return eSink.error(Loc.initial, "ELF object module `%s` is not relocatable", module_name);
if (eh.e_version != EV_CURRENT)
return corrupt(__LINE__);

View file

@ -16,9 +16,9 @@ import core.stdc.stdint;
import dmd.errorsink;
import dmd.location;
//import core.sys.darwin.mach.loader;
import dmd.backend.mach;
import dmd.root.string : fTuple;
nothrow:
@ -31,12 +31,12 @@ private enum LOG = false;
* pAddSymbol = function to pass the names to
* base = array of contents of object module
* module_name = name of the object module (used for error messages)
* loc = location to use for error printing
* filename = object file name for error printing
* eSink = where the error messages go
*/
package(dmd.lib)
void scanMachObjModule(void delegate(const(char)[] name, int pickAny) nothrow pAddSymbol,
const ubyte[] base, const char* module_name, Loc loc, ErrorSink eSink)
const ubyte[] base, const char* module_name, const(char)[] filename, ErrorSink eSink)
{
static if (LOG)
{
@ -45,7 +45,7 @@ void scanMachObjModule(void delegate(const(char)[] name, int pickAny) nothrow pA
void corrupt(int reason)
{
eSink.error(loc, "corrupt Mach-O object module `%s` %d", module_name, reason);
eSink.error(Loc.initial, "corrupt Mach-O object `%.*s` module `%s` %d", filename.fTuple.expand, module_name, reason);
}
const buf = base.ptr;
@ -62,12 +62,12 @@ void scanMachObjModule(void delegate(const(char)[] name, int pickAny) nothrow pA
{
if (header.cputype != CPU_TYPE_I386)
{
eSink.error(loc, "Mach-O object module `%s` has cputype = %d, should be %d", module_name, header.cputype, CPU_TYPE_I386);
eSink.error(Loc.initial, "Mach-O object module `%s` has cputype = %d, should be %d", module_name, header.cputype, CPU_TYPE_I386);
return;
}
if (header.filetype != MH_OBJECT)
{
eSink.error(loc, "Mach-O object module `%s` has file type = %d, should be %d", module_name, header.filetype, MH_OBJECT);
eSink.error(Loc.initial, "Mach-O object module `%s` has file type = %d, should be %d", module_name, header.filetype, MH_OBJECT);
return;
}
if (buflen < mach_header.sizeof + header.sizeofcmds)
@ -81,12 +81,12 @@ void scanMachObjModule(void delegate(const(char)[] name, int pickAny) nothrow pA
return corrupt(__LINE__);
if (header64.cputype != CPU_TYPE_X86_64)
{
eSink.error(loc, "Mach-O object module `%s` has cputype = %d, should be %d", module_name, header64.cputype, CPU_TYPE_X86_64);
eSink.error(Loc.initial, "Mach-O object module `%s` has cputype = %d, should be %d", module_name, header64.cputype, CPU_TYPE_X86_64);
return;
}
if (header64.filetype != MH_OBJECT)
{
eSink.error(loc, "Mach-O object module `%s` has file type = %d, should be %d", module_name, header64.filetype, MH_OBJECT);
eSink.error(Loc.initial, "Mach-O object module `%s` has file type = %d, should be %d", module_name, header64.filetype, MH_OBJECT);
return;
}
if (buflen < mach_header_64.sizeof + header64.sizeofcmds)

View file

@ -18,6 +18,7 @@ import dmd.root.string;
import dmd.errorsink;
import dmd.location;
import dmd.root.string : fTuple;
nothrow:
@ -30,12 +31,12 @@ private enum LOG = false;
* pAddSymbol = function to pass the names to
* base = array of contents of object module
* module_name = name of the object module (used for error messages)
* loc = location to use for error printing
* filename = object file name for error printing
* eSink = where the error messages go
*/
package(dmd.lib)
void scanMSCoffObjModule(void delegate(const(char)[] name, int pickAny) nothrow pAddSymbol,
scope const ubyte[] base, const char* module_name, Loc loc, ErrorSink eSink)
scope const ubyte[] base, const char* module_name, const(char)[] filename, ErrorSink eSink)
{
static if (LOG)
{
@ -44,7 +45,7 @@ void scanMSCoffObjModule(void delegate(const(char)[] name, int pickAny) nothrow
void corrupt(int reason)
{
eSink.error(loc, "corrupt MS-Coff object module `%s` %d", module_name, reason);
eSink.error(Loc.initial, "corrupt MS-Coff object `%.*s` module `%s` %d", filename.fTuple.expand, module_name, reason);
}
const buf = &base[0];
@ -77,16 +78,16 @@ void scanMSCoffObjModule(void delegate(const(char)[] name, int pickAny) nothrow
break;
default:
if (buf[0] == 0x80)
eSink.error(loc, "object module `%s` is 32 bit OMF, but it should be 64 bit MS-Coff", module_name);
eSink.error(Loc.initial, "object module `%s` is 32 bit OMF, but it should be 64 bit MS-Coff", module_name);
else
eSink.error(loc, "MS-Coff object module `%s` has magic = %x, should be %x", module_name, header.Machine, IMAGE_FILE_MACHINE_AMD64);
eSink.error(Loc.initial, "MS-Coff object module `%s` has magic = %x, should be %x", module_name, header.Machine, IMAGE_FILE_MACHINE_AMD64);
return;
}
// Get string table: string_table[0..string_len]
size_t off = header.PointerToSymbolTable;
if (off == 0)
{
eSink.error(loc, "MS-Coff object module `%s` has no string table", module_name);
eSink.error(Loc.initial, "MS-Coff object module `%s` has no string table", module_name);
return;
}
off += header.NumberOfSymbols * (is_old_coff ? SymbolTable.sizeof : SymbolTable32.sizeof);

View file

@ -9,7 +9,7 @@ Use a regex because the path is really strange on Azure (OMF_32, 64):
TEST_OUTPUT:
----
Error: corrupt $?:windows=MS Coff|osx=Mach|ELF$ object module $?:windows=fail_compilation\extra-files\fake.lib|fail_compilation/extra-files/fake.a$ $n$
Error: corrupt $?:windows=MS Coff|osx=Mach|ELF$ object `$r:.*$` module $?:windows=fail_compilation\extra-files\fake.lib|fail_compilation/extra-files/fake.a$ $n$
----
*/
void main() {}