Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 3 additions & 28 deletions src/commandline.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,6 @@ bool IsRelocate(const char* arg) {
return CLICheck(arg, "relocate");
}

bool IsReport(const char* arg) {
return CLICheck(arg, "report");
}

/**
* Parse the command line arguments supportin the relocate command
*/
Expand Down Expand Up @@ -157,32 +153,11 @@ std::map<std::string, std::string> ParseRelocate(const char** args, int argc) {
return opts;
}

std::map<std::string, std::string> ParseReport(int argc, const char** args) {
std::map<std::string, std::string> opts;
for (int i = 0; i < argc; ++i) {
if (endswith(std::string(args[i]), ".dll") ||
endswith(std::string(args[i]), ".exe")) {
if (redefinedArgCheck(opts, "pe", "pe")) {
opts.clear();
return opts;
}
opts.insert(std::pair<std::string, std::string>("pe", args[i]));
} else if (endswith(std::string(args[i]), ".lib")) {
if (redefinedArgCheck(opts, "coff", "coff")) {
opts.clear();
return opts;
}
opts.insert(std::pair<std::string, std::string>("coff", args[i]));
}
}
return opts;
}

bool CheckAndPrintHelp(const char** arg, int argc) {
if (argc < 2) {
bool CheckAndPrintHelp(const char** arg, bool no_args, bool is_relocate) {
if (no_args && is_relocate) {
return print_help();
}
if (strcmp(arg[1], "--help") == 0 || strcmp(arg[1], "-h") == 0) {
if (!no_args && (strcmp(arg[1], "--help") == 0 || strcmp(arg[1], "-h") == 0)) {
return print_help();
}
return false;
Expand Down
10 changes: 1 addition & 9 deletions src/commandline.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,9 @@
// of this executable
bool IsRelocate(const char* arg);

// Determines if a command line invocation is for the report form of this
// Executable
bool IsReport(const char* arg);

// Parses the command line for an invocation of the relocate command
// and returns the arguments mapped from argument name to value
std::map<std::string, std::string> ParseRelocate(const char** args, int argc);

// Parses the command line for an invocation of the report command
// adn returns the arguments mappedfrom argument name to value
std::map<std::string, std::string> ParseReport(int argc, const char** args);

// Writes CLI help message to stdout
bool CheckAndPrintHelp(const char** arg, int argc);
bool CheckAndPrintHelp(const char** arg, bool no_args, bool is_relocate);
5 changes: 5 additions & 0 deletions src/ld.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ DWORD LdInvocation::InvokeToolchain() {
} catch (const FileIOError& e) {
return ExitConditions::FILE_IO_FAILURE;
}
// If there are no arguments (or the argument is just "/?")
// just print help and return
if(link_run.get_input_files().empty() || link_run.isHelp()) {
return ToolChainInvocation::InvokeToolchain();
}

try {
link_run.makeRsp();
Expand Down
11 changes: 10 additions & 1 deletion src/linker_invocation.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ void LinkerInvocation::ProcessTokens(const std::string &normal_token, const std:
this->piped_args_.end()) {
this->piped_args_.at(normal_token).emplace_back(token);
}
else if (normal_token == "?") {
this->is_help_ = true;
}
}


Expand Down Expand Up @@ -113,7 +116,9 @@ void LinkerInvocation::Parse() {
// /NAME
// if no /NAME
// first input file (post rc expansion)

if (this->is_help_ || this->input_files_.empty()) {
return;
}
this->processDefFile();
std::string const ext = this->is_exe_ ? ".exe" : ".dll";
if (this->output_.empty()) {
Expand Down Expand Up @@ -318,3 +323,7 @@ std::string LinkerInvocation::get_mangled_out() const {
bool LinkerInvocation::IsExeLink() const {
return this->is_exe_ || endswith(this->get_out(), ".exe");
}

bool LinkerInvocation::isHelp() const {
return this->is_help_;
}
4 changes: 3 additions & 1 deletion src/linker_invocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class LinkerInvocation {
StrList get_input_files() const;
std::string get_lib_link_args() const;
bool makeRsp();
bool isHelp() const;

private:
void ProcessTokens(const std::string &normal_token, const std::string& token);
Expand All @@ -39,7 +40,8 @@ class LinkerInvocation {
StrList command_files_;
StrList input_files_;
StrList tokens_;
bool is_exe_;
bool is_exe_ = true;
bool is_help_ = false;
std::map<std::string, StrList> piped_args_ = {
{"export", {}}, {"include", {}}, {"libpath", {}},
{"ltcg", {}}, {"machine", {}}, {"nodefaultlib", {}},
Expand Down
33 changes: 4 additions & 29 deletions src/main.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
#include <Intsafe.h>

int main(int argc, const char* argv[]) {

if (CheckAndPrintHelp(argv, argc)) {
const bool is_relocate = IsRelocate(argv[0]);
const bool no_args = argc < 2;
if (CheckAndPrintHelp(argv, no_args, is_relocate)) {
return 0;
}
if (IsRelocate(argv[0])) {
if (is_relocate) {
std::map<std::string, std::string> patch_args =
ParseRelocate(argv + 1, argc - 1);
if (patch_args.empty()) {
Expand Down Expand Up @@ -90,32 +91,6 @@ int main(int argc, const char* argv[]) {
std::cerr << "Library rename failed\n";
return ExitConditions::RENAME_FAILURE;
}
} else if (IsReport(argv[0])) {
std::map<std::string, std::string> report_args =
ParseReport(argc - 1, argv + 1);
if (report_args.empty()) {
std::cerr << "Unable to parse command line for reporting\n"
<< "run command with --help flag for accepted command "
"line arguments\n";
return ExitConditions::CLI_FAILURE;
}
if (report_args.find("pe") != report_args.end()) {
try {
LibRename portable_executable(report_args.at("pe"),
std::string(), false, true);
portable_executable.ExecuteRename();
} catch (const NameTooLongError& e) {
std::cerr
<< "Unable to parse command line for reporting\n"
<< "run command with --help flag for accepted command "
"line arguments\n";
return ExitConditions::CLI_FAILURE;
}
} else {
CoffReaderWriter coff_reader(report_args.at("coff"));
CoffParser coff(&coff_reader);
return static_cast<int>(reportCoff(coff));
}
} else {
// Ensure required variables are set
if (!ValidateSpackEnv()) {
Expand Down
Loading