This is an archive of the discontinued LLVM Phabricator instance.

[LLD][COFF] Reduce chance of symbol name collision with delay-load
ClosedPublic

Authored by alvinhochun on Sep 22 2022, 11:48 AM.

Details

Summary

Delay-loaded imports creats a load thunk with a symbol name. Before this
change, the name uses a __imp_load_ prefix. On the other hand, normal
import uses the __imp_ prefix for the import address pointer. If an
import symbol named load_func is imported normally and another named
func is imported using delay-load, this can cause a symbol name
collision.

This patch changes delay-load imports to use __imp___load_ prefix.
Because it is less likely for normal imports to have a name starting in
__load_ this should reduce the chance of a name collision.

Diff Detail

Event Timeline

alvinhochun created this revision.Sep 22 2022, 11:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 22 2022, 11:48 AM
alvinhochun requested review of this revision.Sep 22 2022, 11:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 22 2022, 11:48 AM

The code was originally added in https://reviews.llvm.org/D87544.

TO be clear, I only made this patch because I came across this code and it seems to be a potential issue. I don't have an actual failing test case here.

mstorsjo accepted this revision.Oct 2 2022, 12:21 AM

Because it is less likely for normal imports to have a name starting in __load_ this should reduce the chance of a name collision.

Indeed, symbols starting with two underscores are reserved for the toolchain implementation, iirc.

This looks reasonable to me.

This revision is now accepted and ready to land.Oct 2 2022, 12:21 AM