Skip to content

Commit c0065f1

Browse files
committed
[ELF] Default to --no-fortran-common
D86142 introduced --fortran-common and defaulted it to true (matching GNU ld but deviates from gold/macOS ld64). The default state was motivated by transparently supporting some FORTRAN 77 programs (Fortran 90 deprecated common blocks). Now I think it again. I believe we made a mistake to change the default: * this is a weird and legacy rule, though the breakage is very small * --fortran-common introduced complexity to parallel symbol resolution and will slow down it * --fortran-common more likely causes issues when users mix COMMON and STB_GLOBAL definitions (see llvm#48570 and https://maskray.me/blog/2022-02-06-all-about-common-symbols). I have seen several issues in our internal projects and Android. On the other hand, --no-fortran-common is safer since COMMON/STB_GLOBAL have the same semantics related to archive member extraction. Therefore I think we should switch back, not punishing the common uage. A platform wanting --fortran-common can implement ld.lld as a shell script wrapper around `lld -flavor gnu --fortran-common "$@"`. Reviewed By: ikudrin, sfertile Differential Revision: https://reviews.llvm.org/D122450
1 parent e78cea0 commit c0065f1

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

lld/ELF/Driver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ static void readConfigs(opt::InputArgList &args) {
10581058
config->fixCortexA8 =
10591059
args.hasArg(OPT_fix_cortex_a8) && !args.hasArg(OPT_relocatable);
10601060
config->fortranCommon =
1061-
args.hasFlag(OPT_fortran_common, OPT_no_fortran_common, true);
1061+
args.hasFlag(OPT_fortran_common, OPT_no_fortran_common, false);
10621062
config->gcSections = args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, false);
10631063
config->gnuUnique = args.hasFlag(OPT_gnu_unique, OPT_no_gnu_unique, true);
10641064
config->gdbIndex = args.hasFlag(OPT_gdb_index, OPT_no_gdb_index, false);

lld/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ ELF Improvements
2828

2929
* ``-z pack-relative-relocs`` is now available to support ``DT_RELR`` for glibc 2.36+.
3030
(`D120701 <https://reviews.llvm.org/D120701>`_)
31+
* ``--no-fortran-common`` (pre 12.0.0 behavior) is now the default.
3132

3233
Breaking changes
3334
----------------

lld/test/ELF/common-archive-lookup.s

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
## Bitcode archive.
2626
# RUN: llvm-ar crs 4.a 1.bc 2.bc
2727

28-
# RUN: ld.lld -o 1 main.o 1.a
28+
# RUN: ld.lld -o 1 main.o 1.a --fortran-common
2929
# RUN: llvm-objdump -D -j .data 1 | FileCheck --check-prefix=TEST1 %s
3030

31-
# RUN: ld.lld -o 2 main.o --start-lib 1.o strong_data_only.o --end-lib
31+
# RUN: ld.lld -o 2 main.o --start-lib 1.o strong_data_only.o --end-lib --fortran-common
3232
# RUN: llvm-objdump -D -j .data 2 | FileCheck --check-prefix=TEST1 %s
3333

3434
# RUN: ld.lld -o 3 main.o 2.a
@@ -45,23 +45,25 @@
4545
# RUN: ld.lld -o 7 main.o 2.o --start-lib 1.o strong_data_only.o --end-lib
4646
# RUN: llvm-objdump -D -j .data 7 | FileCheck --check-prefix=TEST2 %s
4747

48-
# RUN: not ld.lld -o 8 main.o 1.a strong_data_only.o 2>&1 | \
48+
# RUN: not ld.lld -o 8 main.o 1.a strong_data_only.o --fortran-common 2>&1 | \
4949
# RUN: FileCheck --check-prefix=ERR %s
5050

51-
# RUN: not ld.lld -o 9 main.o --start-lib 1.o 2.o --end-lib strong_data_only.o 2>&1 | \
51+
# RUN: not ld.lld -o 9 main.o --start-lib 1.o 2.o --end-lib strong_data_only.o --fortran-common 2>&1 | \
5252
# RUN: FileCheck --check-prefix=ERR %s
5353

5454
# ERR: ld.lld: error: duplicate symbol: block
5555

5656
# RUN: ld.lld --no-fortran-common -o 10 main.o 1.a
5757
# RUN: llvm-readobj --syms 10 | FileCheck --check-prefix=NFC %s
58+
# RUN: ld.lld -o 10 main.o 1.a
59+
# RUN: llvm-readobj --syms 10 | FileCheck --check-prefix=NFC %s
5860

5961
# RUN: ld.lld --no-fortran-common -o 11 main.o --start-lib 1.o strong_data_only.o --end-lib
6062
# RUN: llvm-readobj --syms 11 | FileCheck --check-prefix=NFC %s
6163

62-
# RUN: ld.lld -o - main.o 4.a --lto-emit-asm | FileCheck --check-prefix=ASM %s
64+
# RUN: ld.lld -o - main.o 4.a --fortran-common --lto-emit-asm | FileCheck --check-prefix=ASM %s
6365

64-
# RUN: ld.lld -o - main.o --start-lib 1.bc 2.bc --end-lib --lto-emit-asm | \
66+
# RUN: ld.lld -o - main.o --start-lib 1.bc 2.bc --end-lib --fortran-common --lto-emit-asm | \
6567
# RUN: FileCheck --check-prefix=ASM %s
6668

6769
## COMMON overrides weak. Don't extract 3.bc which provides a weak definition.

lld/test/ELF/warn-backrefs.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
# RUN: llvm-ar rcs %tcomm.a %tcomm.o
7878
# RUN: llvm-ar rcs %tstrong.a %tstrong.o
7979
# RUN: ld.lld --warn-backrefs %tcomm.a %t1.o %t5.o 2>&1 -o /dev/null | FileCheck --check-prefix=COMM %s
80-
# RUN: ld.lld --fatal-warnings --warn-backrefs %tcomm.a %t1.o %t5.o %tstrong.a 2>&1 -o /dev/null
80+
# RUN: ld.lld --fatal-warnings --fortran-common --warn-backrefs %tcomm.a %t1.o %t5.o %tstrong.a 2>&1 -o /dev/null
8181
# RUN: ld.lld --warn-backrefs --no-fortran-common %tcomm.a %t1.o %t5.o %tstrong.a 2>&1 -o /dev/null | FileCheck --check-prefix=COMM %s
8282

8383
# COMM: ld.lld: warning: backward reference detected: obj in {{.*}}5.o refers to {{.*}}comm.a

0 commit comments

Comments
 (0)