summaryrefslogtreecommitdiff
path: root/lib/Object
diff options
context:
space:
mode:
authorMartin Storsjo <martin@martin.st>2017-10-23 09:08:13 +0000
committerMartin Storsjo <martin@martin.st>2017-10-23 09:08:13 +0000
commite893335ed8fab65f7de5584aacd9318efe251cdd (patch)
tree80dcb0f302b19db0d7ab1650f76859051ab2c42c /lib/Object
parent1d7dfd3aadffde91dd5280163ba9acbfda8e7016 (diff)
[COFF] Improve the check for functions that should get an extra underscore
This fixes exporting functions starting with an underscore, and fully decorated fastcall/vectorcall functions. Tests will be added in the lld repo. Differential Revision: https://reviews.llvm.org/D39168 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316316 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Object')
-rw-r--r--lib/Object/COFFModuleDefinition.cpp24
1 files changed, 21 insertions, 3 deletions
diff --git a/lib/Object/COFFModuleDefinition.cpp b/lib/Object/COFFModuleDefinition.cpp
index 510eac8b239..6ea6015eabc 100644
--- a/lib/Object/COFFModuleDefinition.cpp
+++ b/lib/Object/COFFModuleDefinition.cpp
@@ -57,9 +57,27 @@ struct Token {
};
static bool isDecorated(StringRef Sym, bool MingwDef) {
- // mingw does not prepend "_".
- return (!MingwDef && Sym.startswith("_")) || Sym.startswith("@") ||
- Sym.startswith("?");
+ // In def files, the symbols can either be listed decorated or undecorated.
+ //
+ // - For cdecl symbols, only the undecorated form is allowed.
+ // - For fastcall and vectorcall symbols, both fully decorated or
+ // undecorated forms can be present.
+ // - For stdcall symbols in non-MinGW environments, the decorated form is
+ // fully decorated with leading underscore and trailing stack argument
+ // size - like "_Func@0".
+ // - In MinGW def files, a decorated stdcall symbol does not include the
+ // leading underscore though, like "Func@0".
+
+ // This function controls whether a leading underscore should be added to
+ // the given symbol name or not. For MinGW, treat a stdcall symbol name such
+ // as "Func@0" as undecorated, i.e. a leading underscore must be added.
+ // For non-MinGW, look for '@' in the whole string and consider "_Func@0"
+ // as decorated, i.e. don't add any more leading underscores.
+ // We can't check for a leading underscore here, since function names
+ // themselves can start with an underscore, while a second one still needs
+ // to be added.
+ return Sym.startswith("@") || Sym.contains("@@") || Sym.startswith("?") ||
+ (!MingwDef && Sym.contains('@'));
}
static Error createError(const Twine &Err) {