Expected<COFFModuleDefinition>
parseCOFFModuleDefinition(MemoryBufferRef MB, COFF::MachineTypes Machine,
- bool MingwDef = false);
+ bool MingwDef = false, bool AddUnderscores = true);
} // End namespace object.
} // End namespace llvm.
class Parser {
public:
- explicit Parser(StringRef S, MachineTypes M, bool B)
- : Lex(S), Machine(M), MingwDef(B) {}
+ explicit Parser(StringRef S, MachineTypes M, bool B, bool AU)
+ : Lex(S), Machine(M), MingwDef(B), AddUnderscores(AU) {
+ if (Machine != IMAGE_FILE_MACHINE_I386)
+ AddUnderscores = false;
+ }
Expected<COFFModuleDefinition> parse() {
do {
unget();
}
- if (Machine == IMAGE_FILE_MACHINE_I386) {
+ if (AddUnderscores) {
if (!isDecorated(E.Name, MingwDef))
E.Name = (std::string("_").append(E.Name));
if (!E.ExtName.empty() && !isDecorated(E.ExtName, MingwDef))
if (Tok.K == EqualEqual) {
read();
E.AliasTarget = std::string(Tok.Value);
- if (Machine == IMAGE_FILE_MACHINE_I386 && !isDecorated(E.AliasTarget, MingwDef))
+ if (AddUnderscores && !isDecorated(E.AliasTarget, MingwDef))
E.AliasTarget = std::string("_").append(E.AliasTarget);
continue;
}
MachineTypes Machine;
COFFModuleDefinition Info;
bool MingwDef;
+ bool AddUnderscores;
};
Expected<COFFModuleDefinition> parseCOFFModuleDefinition(MemoryBufferRef MB,
MachineTypes Machine,
- bool MingwDef) {
- return Parser(MB.getBuffer(), Machine, MingwDef).parse();
+ bool MingwDef,
+ bool AddUnderscores) {
+ return Parser(MB.getBuffer(), Machine, MingwDef, AddUnderscores).parse();
}
} // namespace object
return 1;
}
- Expected<COFFModuleDefinition> Def =
- parseCOFFModuleDefinition(*MB, Machine, /*MingwDef=*/true);
+ bool AddUnderscores = !Args.hasArg(OPT_no_leading_underscore);
+ Expected<COFFModuleDefinition> Def = parseCOFFModuleDefinition(
+ *MB, Machine, /*MingwDef=*/true, AddUnderscores);
if (!Def) {
llvm::errs() << "error parsing definition\n"
def k: Flag<["-"], "k">, HelpText<"Kill @n Symbol from export">;
def k_alias: Flag<["--"], "kill-at">, Alias<k>;
+def no_leading_underscore: Flag<["--"], "no-leading-underscore">,
+ HelpText<"Don't add leading underscores on symbols">;
+
//==============================================================================
// The flags below do nothing. They are defined only for dlltool compatibility.
//==============================================================================
--- /dev/null
+; RUN: llvm-dlltool -k -m i386 --input-def %s --output-lib %t.a --no-leading-underscore --kill-at
+; RUN: llvm-readobj %t.a | FileCheck %s
+; RUN: llvm-nm %t.a | FileCheck %s -check-prefix=CHECK-NM
+
+LIBRARY test.dll
+EXPORTS
+func
+alias == func
+DecoratedFunction@4
+
+; CHECK: Name type: name
+; CHECK-NEXT: Symbol: __imp_func
+; CHECK-NEXT: Symbol: func
+; CHECK: Name type: undecorate
+; CHECK-NEXT: Symbol: __imp_DecoratedFunction@4
+; CHECK-NEXT: Symbol: DecoratedFunction@4
+
+; CHECK-NM: W alias
+; CHECK-NM: U func