diff --git a/docs/mold.md b/docs/mold.md index 77868d6ca..eaf5445fe 100644 --- a/docs/mold.md +++ b/docs/mold.md @@ -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. diff --git a/elf/cmdline.rs b/elf/cmdline.rs index 5020ceeec..8914f6605 100644 --- a/elf/cmdline.rs +++ b/elf/cmdline.rs @@ -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") { diff --git a/tests/elf/nmagic.sh b/tests/elf/nmagic.sh index 8797cf2d1..092bc900b 100755 --- a/tests/elf/nmagic.sh +++ b/tests/elf/nmagic.sh @@ -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 ] diff --git a/tests/elf/relocatable.sh b/tests/elf/relocatable.sh index 9f16877f1..8f850f4ec 100755 --- a/tests/elf/relocatable.sh +++ b/tests/elf/relocatable.sh @@ -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 diff --git a/tests/elf/trace.sh b/tests/elf/trace.sh index f88d993e3..09fc2b9cc 100755 --- a/tests/elf/trace.sh +++ b/tests/elf/trace.sh @@ -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