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
7 changes: 7 additions & 0 deletions docs/mold.1
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,13 @@ Temporary local symbols are local symbols starting with
Compilers usually generate such symbols for unnamed program elements such as \
string literals or floating-point literals.
.Pp
.It Fl Y Ns Ar dir
Add
.Ar dir
to the list of default search paths from which
.Nm
searches libraries for the \fB-l\fR option.
.Pp
.It Fl e Ar symbol , Fl -entry Ns = Ns Ar symbol
Use
.Ar symbol
Expand Down
8 changes: 8 additions & 0 deletions elf/cmdline.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ static const char helpmsg[] = R"(
-S, --strip-debug Strip .debug_* sections
-T FILE, --script FILE Read linker script
-X, --discard-locals Discard temporary local symbols
-Y DIR Add DIR to default library search path
-e SYMBOL, --entry SYMBOL Set program entry point
-f SHLIB, --auxiliary SHLIB Set DT_AUXILIARY to the specified value
-h LIBNAME, --soname LIBNAME
Expand Down Expand Up @@ -338,6 +339,7 @@ std::vector<std::string> parse_nonpositional_args(Context<E> &ctx) {
ctx.page_size = E::page_size;
ctx.arg.color_diagnostics = isatty(STDERR_FILENO);

std::vector<std::string> default_library_paths;
bool version_shown = false;
bool warn_shared_textrel = false;

Expand Down Expand Up @@ -533,6 +535,8 @@ std::vector<std::string> parse_nonpositional_args(Context<E> &ctx) {
ctx.arg.filler = parse_hex(ctx, "filler", arg);
} else if (read_arg("L") || read_arg("library-path")) {
ctx.arg.library_paths.push_back(std::string(arg));
} else if (read_arg("Y")) {
default_library_paths.push_back(std::string(arg));
} else if (read_arg("sysroot")) {
ctx.arg.sysroot = arg;
} else if (read_arg("unique")) {
Expand Down Expand Up @@ -998,6 +1002,10 @@ std::vector<std::string> parse_nonpositional_args(Context<E> &ctx) {
}
}

ctx.arg.library_paths.insert(ctx.arg.library_paths.end(),
default_library_paths.begin(),
default_library_paths.end());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not fully getting what is difference between -Y and -L options -- at the end, we are just concatenating them.

@rawoul rawoul Feb 27, 2024

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same difference as -isystem and -I, one prepends while the other appends. It's important because build systems usually append your global CFLAGS to the package CFLAGS, so as a distribution or embedded system maintainer, you need a reliable way to know how the system includes will be used. Using a sysroot is sometimes to much of a constraint (because you need to merge the toolchain and the staging rootfs build).

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see now. It does make sense, thanks.


if (!ctx.arg.sysroot.empty()) {
for (std::string &path : ctx.arg.library_paths) {
if (std::string_view(path).starts_with('='))
Expand Down