Add C++11 test programs

This commit is contained in:
Jeffrey Walton 2020-08-05 22:10:31 -04:00
parent 67ad4256e9
commit 1b765d8bd3
No known key found for this signature in database
GPG Key ID: B36AB348921B1838
13 changed files with 229 additions and 174 deletions

View File

@ -58,157 +58,157 @@ const int ErrorWriteException = 7;
void PrintHelpAndExit(int code)
{
std::cout << "dump2def - create a module definitions file from a dumpbin file" << std::endl;
std::cout << " Written and placed in public domain by Jeffrey Walton" << std::endl;
std::cout << std::endl;
std::cout << "dump2def - create a module definitions file from a dumpbin file" << std::endl;
std::cout << " Written and placed in public domain by Jeffrey Walton" << std::endl;
std::cout << std::endl;
switch (code)
{
case ErrorDumpExtension:
std::cout << "Error: input file is missing \".dump\" extension.\n" << std::endl;
break;
case ErrorTooFewOpts:
std::cout << "Error: Too few options were supplied.\n" << std::endl;
break;
case ErrorTooManyOpts:
std::cout << "Error: Too many options were supplied.\n" << std::endl;
break;
case ErrorOpenInputFailed:
std::cout << "Error: Failed to open input file.\n" << std::endl;
break;
case ErrorOpenOutputFailed:
std::cout << "Error: Failed to open output file.\n" << std::endl;
break;
default:
;;
}
switch (code)
{
case ErrorDumpExtension:
std::cout << "Error: input file is missing \".dump\" extension.\n" << std::endl;
break;
case ErrorTooFewOpts:
std::cout << "Error: Too few options were supplied.\n" << std::endl;
break;
case ErrorTooManyOpts:
std::cout << "Error: Too many options were supplied.\n" << std::endl;
break;
case ErrorOpenInputFailed:
std::cout << "Error: Failed to open input file.\n" << std::endl;
break;
case ErrorOpenOutputFailed:
std::cout << "Error: Failed to open output file.\n" << std::endl;
break;
default:
;;
}
std::cout << "Usage: " << std::endl;
std::cout << "Usage: " << std::endl;
std::cout << " dump2def <infile>" << std::endl;
std::cout << " - Create a def file from <infile> and write it to a file with" << std::endl;
std::cout << " the same name as <infile> but using the .def extension" << std::endl;
std::cout << " dump2def <infile>" << std::endl;
std::cout << " - Create a def file from <infile> and write it to a file with" << std::endl;
std::cout << " the same name as <infile> but using the .def extension" << std::endl;
std::cout << " dump2def <infile> <outfile>" << std::endl;
std::cout << " - Create a def file from <infile> and write it to <outfile>" << std::endl;
std::cout << " dump2def <infile> <outfile>" << std::endl;
std::cout << " - Create a def file from <infile> and write it to <outfile>" << std::endl;
std::exit((code == ErrorSuccess ? 0 : 1));
std::exit((code == ErrorSuccess ? 0 : 1));
}
int main(int argc, char* argv[])
{
// ******************** Handle Options ******************** //
// ******************** Handle Options ******************** //
// Convenience item
std::vector<std::string> opts;
for (size_t i=0; i<argc; ++i)
opts.push_back(argv[i]);
// Convenience item
std::vector<std::string> opts;
for (size_t i=0; i<argc; ++i)
opts.push_back(argv[i]);
// Look for help
std::string opt = (opts.size() > 1 ? opts[1].substr(0,2) : "");
if (opt == "/h" || opt == "-h" || opt == "/?" || opt == "-?")
PrintHelpAndExit(ErrorSuccess);
// Look for help
std::string opt = (opts.size() > 1 ? opts[1].substr(0,2) : "");
if (opt == "/h" || opt == "-h" || opt == "/?" || opt == "-?")
PrintHelpAndExit(ErrorSuccess);
// Add <outfile> as needed
if (opts.size() == 2)
{
std::string outfile = opts[1];
std::string::size_type pos = outfile.length() < 5 ? std::string::npos : outfile.length() - 5;
if (pos == std::string::npos || outfile.substr(pos) != ".dump")
PrintHelpAndExit(ErrorDumpExtension);
// Add <outfile> as needed
if (opts.size() == 2)
{
std::string outfile = opts[1];
std::string::size_type pos = outfile.length() < 5 ? std::string::npos : outfile.length() - 5;
if (pos == std::string::npos || outfile.substr(pos) != ".dump")
PrintHelpAndExit(ErrorDumpExtension);
outfile.replace(pos, 5, ".def");
opts.push_back(outfile);
}
outfile.replace(pos, 5, ".def");
opts.push_back(outfile);
}
// Check or exit
if (opts.size() < 2)
PrintHelpAndExit(ErrorTooFewOpts);
if (opts.size() > 3)
PrintHelpAndExit(ErrorTooManyOpts);
// Check or exit
if (opts.size() < 2)
PrintHelpAndExit(ErrorTooFewOpts);
if (opts.size() > 3)
PrintHelpAndExit(ErrorTooManyOpts);
// ******************** Read MAP file ******************** //
// ******************** Read MAP file ******************** //
SymbolMap symbols;
SymbolMap symbols;
try
{
std::ifstream infile(opts[1].c_str());
try
{
std::ifstream infile(opts[1].c_str());
if (infile.is_open() == false)
PrintHelpAndExit(ErrorOpenInputFailed);
if (infile.is_open() == false)
PrintHelpAndExit(ErrorOpenInputFailed);
std::string::size_type pos;
std::string line;
std::string::size_type pos;
std::string line;
// Find start of the symbol table
while (std::getline(infile, line))
{
pos = line.find("public symbols");
if (pos == std::string::npos) { continue; }
// Find start of the symbol table
while (std::getline(infile, line))
{
pos = line.find("public symbols");
if (pos == std::string::npos) { continue; }
// Eat the whitespace after the table heading
infile >> std::ws;
break;
}
// Eat the whitespace after the table heading
infile >> std::ws;
break;
}
while (std::getline(infile, line))
{
// End of table
if (line.empty()) { break; }
while (std::getline(infile, line))
{
// End of table
if (line.empty()) { break; }
std::istringstream iss(line);
std::string address, symbol;
iss >> address >> symbol;
std::istringstream iss(line);
std::string address, symbol;
iss >> address >> symbol;
symbols.insert(symbol);
}
}
catch (const std::exception& ex)
{
std::cerr << "Unexpected exception:" << std::endl;
std::cerr << ex.what() << std::endl;
std::cerr << std::endl;
symbols.insert(symbol);
}
}
catch (const std::exception& ex)
{
std::cerr << "Unexpected exception:" << std::endl;
std::cerr << ex.what() << std::endl;
std::cerr << std::endl;
PrintHelpAndExit(ErrorReadException);
}
PrintHelpAndExit(ErrorReadException);
}
// ******************** Write DEF file ******************** //
// ******************** Write DEF file ******************** //
try
{
std::ofstream outfile(opts[2].c_str());
try
{
std::ofstream outfile(opts[2].c_str());
if (outfile.is_open() == false)
PrintHelpAndExit(ErrorOpenOutputFailed);
if (outfile.is_open() == false)
PrintHelpAndExit(ErrorOpenOutputFailed);
// Library name, cryptopp.dll
std::string name = opts[2];
std::string::size_type pos = name.find_last_of(".");
// Library name, cryptopp.dll
std::string name = opts[2];
std::string::size_type pos = name.find_last_of(".");
if (pos != std::string::npos)
name.erase(pos);
if (pos != std::string::npos)
name.erase(pos);
outfile << "LIBRARY " << name << std::endl;
outfile << "DESCRIPTION \"" << LIBRARY_DESC << "\"" << std::endl;
outfile << "EXPORTS" << std::endl;
outfile << std::endl;
outfile << "LIBRARY " << name << std::endl;
outfile << "DESCRIPTION \"" << LIBRARY_DESC << "\"" << std::endl;
outfile << "EXPORTS" << std::endl;
outfile << std::endl;
outfile << "\t;; " << symbols.size() << " symbols" << std::endl;
outfile << "\t;; " << symbols.size() << " symbols" << std::endl;
// Symbols from our object files
SymbolMap::const_iterator it = symbols.begin();
for ( ; it != symbols.end(); ++it)
outfile << "\t" << *it << std::endl;
}
catch (const std::exception& ex)
{
std::cerr << "Unexpected exception:" << std::endl;
std::cerr << ex.what() << std::endl;
std::cerr << std::endl;
// Symbols from our object files
SymbolMap::const_iterator it = symbols.begin();
for ( ; it != symbols.end(); ++it)
outfile << "\t" << *it << std::endl;
}
catch (const std::exception& ex)
{
std::cerr << "Unexpected exception:" << std::endl;
std::cerr << ex.what() << std::endl;
std::cerr << std::endl;
PrintHelpAndExit(ErrorWriteException);
}
PrintHelpAndExit(ErrorWriteException);
}
return 0;
return 0;
}

View File

@ -8,23 +8,23 @@ int main(int argc, char* argv[])
asm __volatile__
(
#if defined(__amd64__) || defined(__x86_64__)
".intel_syntax noprefix ;\n"
"xor rsi, rsi ;\n"
"neg %1 ;\n"
"inc %1 ;\n"
"push %1 ;\n"
"pop rax ;\n"
".att_syntax prefix ;\n"
: "=a" (ret) : "c" (N) : "%rsi"
".intel_syntax noprefix ;\n"
"xor rsi, rsi ;\n"
"neg %1 ;\n"
"inc %1 ;\n"
"push %1 ;\n"
"pop rax ;\n"
".att_syntax prefix ;\n"
: "=a" (ret) : "c" (N) : "%rsi"
#else
".intel_syntax noprefix ;\n"
"xor esi, esi ;\n"
"neg %1 ;\n"
"inc %1 ;\n"
"push %1 ;\n"
"pop eax ;\n"
".att_syntax prefix ;\n"
: "=a" (ret) : "c" (N) : "%esi"
".intel_syntax noprefix ;\n"
"xor esi, esi ;\n"
"neg %1 ;\n"
"inc %1 ;\n"
"push %1 ;\n"
"pop eax ;\n"
".att_syntax prefix ;\n"
: "=a" (ret) : "c" (N) : "%esi"
#endif
);
return (int)ret;

View File

@ -0,0 +1,5 @@
int main(int argc, char* argv[])
{
alignas(16) unsigned char x[16];
return 0;
}

View File

@ -0,0 +1,6 @@
#include <cstddef>
int main (int argc, char* argv[])
{
std::size_t n = alignof(int);
return 0;
}

View File

@ -0,0 +1,7 @@
#include <atomic>
int main(int argc, char* argv[])
{
std::atomic_flag f = ATOMIC_FLAG_INIT;
std::atomic<bool> g (false);
return 0;
}

View File

@ -0,0 +1,10 @@
struct S {
S() = delete;
explicit S(int n) { }
};
int main (int argc, char* rgv[])
{
S s(1);
return 0;
}

View File

@ -0,0 +1,10 @@
// https://en.cppreference.com/w/cpp/feature_test
int main(int argc, char* argv[])
{
#if __cpp_threadsafe_static_init >= 200806L
int x[1];
#else
int x[-1];
#endif
return 0;
}

View File

@ -0,0 +1,10 @@
// https://en.cppreference.com/w/cpp/feature_test
int main(int argc, char* argv[])
{
#if __cpp_lambdas >= 200907L
int x[1];
#else
int x[-1];
#endif
return 0;
}

View File

@ -0,0 +1,7 @@
#include <mutex>
int main(int argc, char* argv[])
{
static std::mutex m;
std::lock_guard<std::mutex> l(m);
return 0;
}

View File

@ -2,4 +2,4 @@
int main(int argc, char* argv[])
{
return 0 == std::uncaught_exceptions() ? 0 : 1;
}
}

View File

@ -9,29 +9,29 @@ int main(int argc, char* argv[])
__asm__ __volatile__
(
#if defined(__x86_64__) || defined(__amd64__)
"mov %1, %%rdi ;\n"
"movl %2, %%edx ;\n"
"mov %1, %%rdi ;\n"
"movl %2, %%edx ;\n"
#else
"mov %1, %%edi ;\n"
"movl %2, %%edx ;\n"
"mov %1, %%edi ;\n"
"movl %2, %%edx ;\n"
#endif
// xstore-rng
".byte 0x0f, 0xa7, 0xc0 ;\n"
// xstore-rng
".byte 0x0f, 0xa7, 0xc0 ;\n"
#if defined(__x86_64__) || defined(__amd64__)
"andq %%rax, 0x1f ;\n"
"movl %%eax, %0 ;\n"
"andq %%rax, 0x1f ;\n"
"movl %%eax, %0 ;\n"
#else
"andl %%eax, 0x1f ;\n"
"movl %%eax, %0 ;\n"
"andl %%eax, 0x1f ;\n"
"movl %%eax, %0 ;\n"
#endif
: "=g" (msr) : "g" (buffer), "g" (divisor)
: "=g" (msr) : "g" (buffer), "g" (divisor)
#if defined(__x86_64__) || defined(__amd64__)
: "rax", "rdx", "rdi", "cc"
: "rax", "rdx", "rdi", "cc"
#else
: "eax", "edx", "edi", "cc"
: "eax", "edx", "edi", "cc"
#endif
);

View File

@ -8,29 +8,29 @@ int main(int argc, char* argv[])
__asm__ __volatile__
(
#if defined(__x86_64__) || defined(__amd64__)
"mov %1, %%rdi ;\n"
"movl %2, %%edx ;\n"
"mov %1, %%rdi ;\n"
"movl %2, %%edx ;\n"
#else
"mov %1, %%edi ;\n"
"movl %2, %%edx ;\n"
"mov %1, %%edi ;\n"
"movl %2, %%edx ;\n"
#endif
// xstore-rng
".byte 0x0f, 0xa7, 0xc0 ;\n"
// xstore-rng
".byte 0x0f, 0xa7, 0xc0 ;\n"
#if defined(__x86_64__) || defined(__amd64__)
"andq %%rax, 0x1f ;\n"
"movl %%eax, %0 ;\n"
"andq %%rax, 0x1f ;\n"
"movl %%eax, %0 ;\n"
#else
"andl %%eax, 0x1f ;\n"
"movl %%eax, %0 ;\n"
"andl %%eax, 0x1f ;\n"
"movl %%eax, %0 ;\n"
#endif
: "=g" (msr) : "g" (buffer), "g" (divisor)
: "=g" (msr) : "g" (buffer), "g" (divisor)
#if defined(__x86_64__) || defined(__amd64__)
: "rax", "rdx", "rdi", "cc"
: "rax", "rdx", "rdi", "cc"
#else
: "eax", "edx", "edi", "cc"
: "eax", "edx", "edi", "cc"
#endif
);

View File

@ -9,29 +9,29 @@ int main(int argc, char* argv[])
__asm__ __volatile__
(
#if defined(__x86_64__) || defined(__amd64__)
"mov %1, %%rdi ;\n"
"movl %2, %%edx ;\n"
"mov %1, %%rdi ;\n"
"movl %2, %%edx ;\n"
#else
"mov %1, %%edi ;\n"
"movl %2, %%edx ;\n"
"mov %1, %%edi ;\n"
"movl %2, %%edx ;\n"
#endif
// xstore-rng
".byte 0x0f, 0xa7, 0xc0 ;\n"
// xstore-rng
".byte 0x0f, 0xa7, 0xc0 ;\n"
#if defined(__x86_64__) || defined(__amd64__)
"andq %%rax, 0x1f ;\n"
"movl %%eax, %0 ;\n"
"andq %%rax, 0x1f ;\n"
"movl %%eax, %0 ;\n"
#else
"andl %%eax, 0x1f ;\n"
"movl %%eax, %0 ;\n"
"andl %%eax, 0x1f ;\n"
"movl %%eax, %0 ;\n"
#endif
: "=g" (msr) : "g" (buffer), "g" (divisor)
: "=g" (msr) : "g" (buffer), "g" (divisor)
#if defined(__x86_64__) || defined(__amd64__)
: "rax", "rdx", "rdi", "cc"
: "rax", "rdx", "rdi", "cc"
#else
: "eax", "edx", "edi", "cc"
: "eax", "edx", "edi", "cc"
#endif
);