#include "gold.h"
+#include <cstdlib>
#include <iostream>
#include <sys/stat.h>
#include "filenames.h"
#include "libiberty.h"
+#include "debug.h"
#include "options.h"
namespace gold
void (General_options::*set)();
};
+// We have a separate table for --debug options.
+
+struct options::One_debug_option
+{
+ // The name of the option.
+ const char* name;
+
+ // The flags to turn on.
+ unsigned int debug_flags;
+};
+
class options::Command_line_options
{
public:
static const int options_size;
static const One_z_option z_options[];
static const int z_options_size;
+ static const One_debug_option debug_options[];
+ static const int debug_options_size;
};
} // End namespace gold.
std::puts(options[i].doc);
}
- ::exit(0);
+ ::exit(EXIT_SUCCESS);
return 0;
}
version(int, char**, char* opt, bool, gold::Command_line*)
{
gold::print_version(opt[0] == 'v' && opt[1] == '\0');
- ::exit(0);
+ ::exit(EXIT_SUCCESS);
return 0;
}
const options::One_option
options::Command_line_options::options[] =
{
+ GENERAL_NOARG('\0', "allow-shlib-undefined",
+ N_("Allow unresolved references in shared libraries"),
+ NULL, TWO_DASHES,
+ &General_options::set_allow_shlib_undefined),
+ GENERAL_NOARG('\0', "no-allow-shlib-undefined",
+ N_("Do not allow unresolved references in shared libraries"),
+ NULL, TWO_DASHES,
+ &General_options::set_no_allow_shlib_undefined),
POSDEP_NOARG('\0', "as-needed",
N_("Only set DT_NEEDED for dynamic libs if used"),
NULL, TWO_DASHES, &Position_dependent_options::set_as_needed),
&Position_dependent_options::set_static_search),
GENERAL_NOARG('\0', "Bsymbolic", N_("Bind defined symbols locally"),
NULL, ONE_DASH, &General_options::set_symbolic),
+#ifdef HAVE_ZLIB_H
+# define ZLIB_STR ",zlib"
+#else
+# define ZLIB_STR ""
+#endif
+ GENERAL_ARG('\0', "compress-debug-sections",
+ N_("Compress .debug_* sections in the output file "
+ "(default is none)"),
+ N_("--compress-debug-sections=[none" ZLIB_STR "]"),
+ TWO_DASHES,
+ &General_options::set_compress_debug_sections),
+ GENERAL_NOARG('\0', "demangle", N_("Demangle C++ symbols in log messages"),
+ NULL, TWO_DASHES, &General_options::set_demangle),
+ GENERAL_NOARG('\0', "no-demangle",
+ N_("Do not demangle C++ symbols in log messages"),
+ NULL, TWO_DASHES, &General_options::clear_demangle),
GENERAL_NOARG('\0', "detect-odr-violations",
N_("Try to detect violations of the One Definition Rule"),
NULL, TWO_DASHES, &General_options::set_detect_odr_violations),
&General_options::add_to_rpath_link),
GENERAL_NOARG('s', "strip-all", N_("Strip all symbols"), NULL,
TWO_DASHES, &General_options::set_strip_all),
+ GENERAL_NOARG('\0', "strip-debug-gdb",
+ N_("Strip debug symbols that are unused by gdb "
+ "(at least versions <= 6.7)"),
+ NULL, TWO_DASHES, &General_options::set_strip_debug_gdb),
+ // This must come after -Sdebug since it's a prefix of it.
GENERAL_NOARG('S', "strip-debug", N_("Strip debugging information"), NULL,
TWO_DASHES, &General_options::set_strip_debug),
GENERAL_NOARG('\0', "shared", N_("Generate shared library"),
SPECIAL('\0', "help", N_("Report usage information"), NULL,
TWO_DASHES, &help),
SPECIAL('v', "version", N_("Report version information"), NULL,
- TWO_DASHES, &version)
+ TWO_DASHES, &version),
+ GENERAL_ARG('\0', "debug", N_("Turn on debugging (all,task)"),
+ N_("--debug=TYPE"), TWO_DASHES,
+ &General_options::handle_debug_option)
};
const int options::Command_line_options::options_size =
const int options::Command_line_options::z_options_size =
sizeof(z_options) / sizeof(z_options[0]);
+// The --debug options.
+
+const options::One_debug_option
+options::Command_line_options::debug_options[] =
+{
+ { "all", DEBUG_ALL },
+ { "task", DEBUG_TASK },
+};
+
+const int options::Command_line_options::debug_options_size =
+ sizeof(debug_options) / sizeof(debug_options[0]);
+
// The default values for the general options.
General_options::General_options()
output_file_name_("a.out"),
is_relocatable_(false),
strip_(STRIP_NONE),
+ allow_shlib_undefined_(false),
symbolic_(false),
+ compress_debug_sections_(NO_COMPRESSION),
detect_odr_violations_(false),
create_eh_frame_hdr_(false),
rpath_(),
thread_count_initial_(0),
thread_count_middle_(0),
thread_count_final_(0),
- execstack_(EXECSTACK_FROM_INPUT)
+ execstack_(EXECSTACK_FROM_INPUT),
+ debug_(0)
{
+ // We initialize demangle_ based on the environment variable
+ // COLLECT_NO_DEMANGLE. The gcc collect2 program will demangle the
+ // output of the linker, unless COLLECT_NO_DEMANGLE is set in the
+ // environment. Acting the same way here lets us provide the same
+ // interface by default.
+ this->demangle_ = getenv("COLLECT_NO_DEMANGLE") == NULL;
}
// The default values for the position dependent options.
fprintf(stderr, _("%s: unrecognized -z subcommand: %s\n"),
program_name, arg);
- ::exit(1);
+ ::exit(EXIT_FAILURE);
+}
+
+// Handle the --debug option.
+
+void
+General_options::handle_debug_option(const char* arg)
+{
+ const int debug_options_size =
+ options::Command_line_options::debug_options_size;
+ const gold::options::One_debug_option* debug_options =
+ options::Command_line_options::debug_options;
+ for (int i = 0; i < debug_options_size; ++i)
+ {
+ if (strcmp(arg, debug_options[i].name) == 0)
+ {
+ this->set_debug(debug_options[i].debug_flags);
+ return;
+ }
+ }
+
+ fprintf(stderr, _("%s: unrecognized --debug subcommand: %s\n"),
+ program_name, arg);
+ ::exit(EXIT_FAILURE);
}
// Add the sysroot, if any, to the search paths.
fprintf(stderr,
_("%s: use the --help option for usage information\n"),
program_name);
- ::exit(1);
+ ::exit(EXIT_FAILURE);
}
void