Skip to content

[LLD] MinGW driver __image_base__ alternate name wrongly defined on i386 if no -m option from gcc #134558

@jeremyd2019

Description

@jeremyd2019

in lld/MinGW/Driver.cpp, there is:

if (args.getLastArgValue(OPT_m) == "i386pe")
add("-alternatename:__image_base__=___ImageBase");
else
add("-alternatename:__image_base__=__ImageBase");

This does not seem to work in the default case:

$ g++ hello.cc -fuse-ld=lld
warning: failed to compute relocation: IMAGE_REL_I386_REL32, Invalid data was encountered while parsing the file
ld.lld: error: undefined symbol: __image_base__
>>> referenced by /t/r/msys2-runtime-3.3/src/msys2-runtime/winsup/cygwin/lib/_cygwin_crt0_common.cc:188
>>>               libmsys-2.0.a(_cygwin_crt0_common.o):(.text)
collect2: error: ld returned 1 exit status

As a workaround I can do:

$ g++ hello.cc -fuse-ld=lld -Wl,-m,i386pe

$ ./a.exe
Hello

@mstorsjo @mati865

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions