[go: up one dir, main page]

Skip to content

Commit

Permalink
Merge pull request #467 from Hind-M/linker_options
Browse files Browse the repository at this point in the history
Fix options passed to the linker
  • Loading branch information
JohanMabille committed Dec 26, 2022
2 parents 79d2bb8 + b3b65a0 commit 7568188
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
11 changes: 2 additions & 9 deletions docs/source/magics.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,10 @@ the cell is used for the body of the `main` function.

- Optional arguments:

Any additional argument is passed to the linker. In particular this can be used
with `-l` to link extra libraries that have otherwise been loaded with

.. code::
#pragma cling load("...")
Furthermore some options influence code generation:
You can use the following options which will be passed to the linker and will influence code generation:

+-------------------+---------------------------------------------+
| -fsanitize=thread | enable instrumentation with ThreadSanitizer |
| -fsanitize | enable instrumentation with ThreadSanitizer |
+-------------------+---------------------------------------------+
| -g | enable debug information in the executable |
+-------------------+---------------------------------------------+
Expand Down
26 changes: 14 additions & 12 deletions src/xmagics/executable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,14 @@ namespace xcpp
argpars.add_argument("filename")
.help("filename")
.required();
argpars.add_argument("options")
.help("options")
.default_value<std::vector<std::string>>({ "" });
argpars.add_argument("-g")
.help("linker options: enable debug information in the executable")
.default_value(false)
.implicit_value(true);
argpars.add_argument("-fsanitize")
.help("linker options: enable instrumentation with ThreadSanitizer using \'-fsanitize=thread\'")
.default_value(false)
.implicit_value(true);
// Add custom help (does not call `exit` avoiding to restart the kernel)
argpars.add_argument("-h", "--help")
.action([&](const std::string & /*unused*/)
Expand Down Expand Up @@ -264,8 +269,6 @@ namespace xcpp
argpars.parse(line);

std::string ExeFile = argpars.get<std::string>("filename");
std::vector<std::string> LinkerOptions =
argpars.get<std::vector<std::string>>("options");

std::string main, unique_fn;
generate_fns(cell, main, unique_fn);
Expand Down Expand Up @@ -299,20 +302,18 @@ namespace xcpp
}
unloader(m_interpreter, *t);

std::vector<std::string> LinkerOptions;
// Enable debug information if user requested -g in the linker options.
bool EnableDebugInfo =
(std::find(LinkerOptions.begin(), LinkerOptions.end(),
"-g") != LinkerOptions.end());
bool EnableDebugInfo = argpars.is_used("-g");
if (EnableDebugInfo)
{
std::cout << "Enabling debug information" << std::endl;
LinkerOptions.push_back("-g");
}

// Enable TSan instrumentation if user requested -fsanitize=thread in
// Enable TSan instrumentation if user requested -fsanitize in
// the linker options.
bool SanitizeThread =
(std::find(LinkerOptions.begin(), LinkerOptions.end(),
"-fsanitize=thread") != LinkerOptions.end());
bool SanitizeThread = argpars.is_used("-fsanitize");
auto& SanitizeOpts = m_interpreter.getCI()->getLangOpts().Sanitize;
if (SanitizeThread)
{
Expand All @@ -323,6 +324,7 @@ namespace xcpp
// Imply debug information because it gives the user a clue which
// line of the input caused the race.
EnableDebugInfo = true;
LinkerOptions.push_back("-fsanitize=thread");
}

std::cout << "Writing executable to " << ExeFile << std::endl;
Expand Down

0 comments on commit 7568188

Please sign in to comment.