Skip to content

Commit

Permalink
Merge pull request #9284 from dra27/ocamlrun-config
Browse files Browse the repository at this point in the history
Add -config option to ocamlrun
  • Loading branch information
dra27 committed Jan 5, 2021
2 parents be48244 + bb59a99 commit 2118969
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 6 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ Working version

### Runtime system:

- #9284: Add -config option to display the configuration of ocamlrun on stdout,
including the search path for shared stub libraries.
(David Allsopp, review by Xavier Leroy)

- #10025: Track custom blocks (e.g. Bigarray) with Statmemprof
(Stephen Dolan, review by Leo White, Gabriel Scherer and Jacques-Henri
Jourdan)
Expand Down
3 changes: 3 additions & 0 deletions manual/manual/cmds/runtime.etex
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ back trace is printed only if the bytecode executable contains
debugging information, i.e. was compiled and linked with the "-g"
option to "ocamlc" set. This is equivalent to setting the "b" flag
in the "OCAMLRUNPARAM" environment variable (see below).
\item["-config"]
Print the version number of "ocamlrun" and a detailed summary of its
configuration, then exit.
\item["-I" \var{dir}]
Search the directory \var{dir} for dynamically-loaded libraries,
in addition to the standard search path (see
Expand Down
2 changes: 2 additions & 0 deletions runtime/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,8 @@ $(foreach object_type, $(object_types), \

dynlink.%.$(O): OC_CPPFLAGS += $(STDLIB_CPP_FLAG)

startup_byt.%.$(O): OC_CPPFLAGS += $(STDLIB_CPP_FLAG) -DHOST='"$(HOST)"'

$(foreach object_type,$(subst %,,$(object_types)), \
$(eval dynlink$(object_type).$(O): $(ROOTDIR)/Makefile.config))

Expand Down
6 changes: 6 additions & 0 deletions runtime/caml/dynlink.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ extern void caml_build_primitive_table_builtin(void);
/* Unload all the previously loaded shared libraries */
extern void caml_free_shared_libs(void);

/* Return the effective location of the standard library */
extern char_os * caml_get_stdlib_location(void);

/* Parse ld.conf and add the lines read to caml_shared_libs_path */
extern char_os * caml_parse_ld_conf(void);

#endif /* CAML_INTERNALS */

#endif /* CAML_DYNLINK_H */
19 changes: 13 additions & 6 deletions runtime/dynlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,21 @@ static c_primitive lookup_primitive(char * name)
return NULL;
}

/* Parse the OCAML_STDLIB_DIR/ld.conf file and add the directories
/* Parse the ld.conf file and add the directories
listed there to the search path */

#define LD_CONF_NAME T("ld.conf")

static char_os * parse_ld_conf(void)
CAMLexport char_os * caml_get_stdlib_location(void)
{
char_os * stdlib;
stdlib = caml_secure_getenv(T("OCAMLLIB"));
if (stdlib == NULL) stdlib = caml_secure_getenv(T("CAMLLIB"));
if (stdlib == NULL) stdlib = OCAML_STDLIB_DIR;
return stdlib;
}

CAMLexport char_os * caml_parse_ld_conf(void)
{
char_os * stdlib, * ldconfname, * wconfig, * p, * q;
char * config;
Expand All @@ -86,9 +95,7 @@ static char_os * parse_ld_conf(void)
#endif
int ldconf, nread;

stdlib = caml_secure_getenv(T("OCAMLLIB"));
if (stdlib == NULL) stdlib = caml_secure_getenv(T("CAMLLIB"));
if (stdlib == NULL) stdlib = OCAML_STDLIB_DIR;
stdlib = caml_get_stdlib_location();
ldconfname = caml_stat_strconcat_os(3, stdlib, T("/"), LD_CONF_NAME);
if (stat_os(ldconfname, &st) == -1) {
caml_stat_free(ldconfname);
Expand Down Expand Up @@ -169,7 +176,7 @@ void caml_build_primitive_table(char_os * lib_path,
if (lib_path != NULL)
for (p = lib_path; *p != 0; p += strlen_os(p) + 1)
caml_ext_table_add(&caml_shared_libs_path, p);
tofree2 = parse_ld_conf();
tofree2 = caml_parse_ld_conf();
/* Open the shared libraries */
caml_ext_table_init(&shared_libs, 8);
if (libs != NULL)
Expand Down
80 changes: 80 additions & 0 deletions runtime/startup_byt.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@

static char magicstr[EXEC_MAGIC_LENGTH+1];
static int print_magic = 0;
static int print_config = 0;

/* Print the specified error message followed by an end-of-line and exit */
static void error(char *msg, ...)
Expand Down Expand Up @@ -279,6 +280,7 @@ static void do_print_help(void)
"Usage: ocamlrun [<options>] [--] <executable> [<command-line>]\n"
"Options are:\n"
" -b Set runtime parameter b (detailed exception backtraces)\n"
" -config Print configuration values and exit\n"
" -I <dir> Add <dir> to the list of DLL search directories\n"
" -m Print the magic number of <executable> and exit\n"
" -M Print the magic number expected by this runtime and exit\n"
Expand Down Expand Up @@ -351,6 +353,8 @@ static int parse_command_line(char_os **argv)
!strcmp_os(argv[i], T("--help"))) {
do_print_help();
exit(0);
} else if (!strcmp_os(argv[i], T("-config"))) {
print_config = 1;
} else {
parsed = 0;
}
Expand All @@ -363,6 +367,78 @@ static int parse_command_line(char_os **argv)
return i;
}

/* Print the configuration of the runtime to stdout; memory allocated is not
freed, since the runtime will terminate after calling this. */
static void do_print_config(void)
{
int i;
char_os * dir;

/* Print the runtime configuration */
printf("version: %s\n", OCAML_VERSION_STRING);
printf("standard_library_default: %s\n",
caml_stat_strdup_of_os(OCAML_STDLIB_DIR));
printf("standard_library: %s\n",
caml_stat_strdup_of_os(caml_get_stdlib_location()));
printf("int_size: %d\n", 8 * (int)sizeof(value));
printf("word_size: %d\n", 8 * (int)sizeof(value) - 1);
printf("os_type: %s\n", OCAML_OS_TYPE);
printf("host: %s\n", HOST);
printf("flat_float_array: %s\n",
#ifdef FLAT_FLOAT_ARRAY
"true");
#else
"false");
#endif
printf("supports_afl: %s\n",
#ifdef HAS_SYS_SHM_H
"true");
#else
"false");
#endif
printf("windows_unicode: %s\n",
#if WINDOWS_UNICODE
"true");
#else
"false");
#endif
printf("supports_shared_libraries: %s\n",
#ifdef SUPPORT_DYNAMIC_LINKING
"true");
#else
"false");
#endif
printf("no_naked_pointers: %s\n",
#ifdef NO_NAKED_POINTERS
"true");
#else
"false");
#endif
printf("profinfo: %s\n"
"profinfo_width: %d\n",
#ifdef WITH_PROFINFO
"true", PROFINFO_WIDTH);
#else
"false", 0);
#endif
printf("exec_magic_number: %s\n", EXEC_MAGIC);

/* Parse ld.conf and print the effective search path */
puts("shared_libs_path:");
caml_parse_ld_conf();
for (i = 0; i < caml_shared_libs_path.size; i++) {
dir = caml_shared_libs_path.contents[i];
if (dir[0] == 0)
#ifdef _WIN32
/* See caml_search_in_path in win32.c */
continue;
#else
dir = ".";
#endif
printf(" %s\n", caml_stat_strdup_of_os(dir));
}
}

#ifdef _WIN32
extern void caml_signal_thread(void * lpParam);
#endif
Expand Down Expand Up @@ -428,6 +504,10 @@ CAMLexport void caml_main(char_os **argv)

if (fd < 0) {
pos = parse_command_line(argv);
if (print_config) {
do_print_config();
exit(0);
}
if (argv[pos] == 0) {
error("no bytecode file specified");
}
Expand Down

0 comments on commit 2118969

Please sign in to comment.