Accept GNU ld's -t, -n and -i

They are GNU ld's short names for --trace, --nmagic and -r.

https://github.com/rui314/mold/pull/1731.
This commit is contained in:
Rui Ueyama committed 2026-10-11 09:01:06 +09:00
1 parent 1247d53089
commit 246390167b
5 files changed
+25 -10

No files matched your search

+7 -4
View File
@@ -417,10 +417,13 @@ point symbol in a script.
* `-m` _target_:
Choose a _target_.
* `-n`, `--nmagic`, `--no-nmagic`:
Do not align sections to page boundaries.
* `-o` _file_, `--output`=_file_:
Use _file_ as the output file name instead of the default name `a.out`.
* `-r`, `--relocatable`:
* `-r`, `-i`, `--relocatable`:
Instead of generating an executable or a shared object file, combine input
object files to generate another object file that can be used as an input to
a linker.
@@ -428,6 +431,9 @@ point symbol in a script.
* `-s`, `--strip-all`:
Omit `.symtab` section from the output file.
* `-t`, `--trace`:
Print name of each input file.
* `-u` _symbol_, `--undefined`=_symbol_:
If _symbol_ remains as an undefined symbol after reading all object files,
and if there is a static archive that contains an object file defining
@@ -784,9 +790,6 @@ point symbol in a script.
* `--sysroot`=_dir_:
Set target system root directory to _dir_.
* `--trace`:
Print name of each input file.
* `--undefined-glob`=_pattern_:
Synonym for `--undefined`, except that `--undefined-glob` takes a glob
pattern instead of just a single symbol name.
+9 -6
View File
@@ -52,10 +52,13 @@ Options:
-l LIBNAME, --library LIBNAME
Search for a given library
-m TARGET Set target
-n, --nmagic Do not page align sections
--no-nmagic
-o FILE, --output FILE Set output filename
-q, --emit-relocs Leaves relocation sections in the output
-r, --relocatable Generate relocatable output
-r, -i, --relocatable Generate relocatable output
-s, --strip-all Strip .symtab section
-t, --trace Print the name of each input file
-u SYMBOL, --undefined SYMBOL
Force to resolve SYMBOL
-w, --no-warnings Suppress warnings
@@ -128,8 +131,6 @@ Options:
--init SYMBOL Call SYMBOL at load-time
--mmap-output-file Write the output file using mmap (default)
--no-mmap-output-file
--nmagic Do not page align sections
--no-nmagic
--no-undefined Report undefined symbols (even with --shared)
--noinhibit-exec Create an output file even if errors occur
--oformat=binary Omit ELF, section, and program headers
@@ -177,7 +178,6 @@ Options:
Use COUNT number of threads
--threads Use multiple threads (default)
--no-threads
--trace Print the name of each input file
--undefined-glob PATTERN Force to resolve all symbols that match a given pattern
--undefined-version Do not report version scripts that refer to undefined symbols
--no-undefined-version Report version scripts that refer to undefined symbols (default)
@@ -1395,7 +1395,7 @@ pub fn parse_args(target: &TargetTraits, raw_cmdline: &[Cow<'_, OsStr>]) -> Pars
cursor.read_switch("apply-dynamic-relocs", "no-apply-dynamic-relocs")
{
a.apply_dynamic_relocs = value;
} else if cursor.read_flag("trace") {
} else if cursor.read_flag("trace") || cursor.read_flag("t") {
a.trace = true;
} else if let Some(value) = cursor.read_switch("eh-frame-hdr", "no-eh-frame-hdr") {
a.eh_frame_hdr = value;
@@ -1412,7 +1412,8 @@ pub fn parse_args(target: &TargetTraits, raw_cmdline: &[Cow<'_, OsStr>]) -> Pars
a.relax = value;
} else if let Some(value) = cursor.read_switch("gdb-index", "no-gdb-index") {
a.gdb_index = value;
} else if cursor.read_flag("r") || cursor.read_flag("relocatable") {
} else if cursor.read_flag("r") || cursor.read_flag("i") || cursor.read_flag("relocatable")
{
a.relocatable = true;
a.emit_relocs = true;
} else if cursor.read_flag("relocatable-merge-sections") {
@@ -1674,6 +1675,8 @@ pub fn parse_args(target: &TargetTraits, raw_cmdline: &[Cow<'_, OsStr>]) -> Pars
a.z_rewrite_endbr = false;
} else if let Some(value) = cursor.read_switch("nmagic", "no-nmagic") {
a.nmagic = value;
} else if cursor.read_flag("n") {
a.nmagic = true;
} else if cursor.read_flag("fatal-warnings") {
mold_common::error::set_fatal_warnings(true);
} else if cursor.read_flag("no-fatal-warnings") {
+3
View File
@@ -7,8 +7,11 @@ EOF
$CC -B. -o $t/exe1 $t/a.o -nostdlib -Wl,-nmagic
$CC -B. -o $t/exe2 $t/a.o -nostdlib
$CC -B. -o $t/exe3 $t/a.o -nostdlib -Wl,-n
end1=$(nm $t/exe1 | grep ' end$' | cut -d' ' -f1)
end2=$(nm $t/exe2 | grep ' end$' | cut -d' ' -f1)
end3=$(nm $t/exe3 | grep ' end$' | cut -d' ' -f1)
[ $((0x$end1)) -lt $((0x$end2)) ]
[ $end1 = $end3 ]
+3
View File
@@ -18,3 +18,6 @@ EOF
$CC -B. -o $t/exe $t/c.o
$QEMU $t/exe
./mold -i -o $t/d.o $t/a.o $t/b.o
cmp $t/c.o $t/d.o
+3
View File
@@ -12,3 +12,6 @@ EOF
$CC -B. -o $t/exe $t/a.o -Wl,-trace > $t/log
grep '/a\.o$' $t/log
$CC -B. -o $t/exe $t/a.o -Wl,-t > $t/log2
grep '/a\.o$' $t/log2