<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/78948>78948</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Linker fails, big local array with SAVE attribute.
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            bug,
            flang:runtime
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          kiranktp
      </td>
    </tr>
</table>

<pre>
    [Flang] Linker fails, big local array with SAVE attribute.

Here is the reproducer:
cat -n repro.F90
     1  Program test_linker
     2 Call s()
     3    Print '("ok")'
     4  Contains
     5 Subroutine s()
     6      Real(kind(1.d0)),Save :: x(1:10**9)
     7 End Subroutine s
     8  End Program test_linker

$ flang-new repro.F90
/home/llvm-flang-src/install/lib/libFortranRuntime.a(unit.cpp.o): in function `Fortran::runtime::io::CloseAllExternalUnits()':
unit.cpp:(.text._ZN7Fortran7runtime2ioL21CloseAllExternalUnitsEv+0x8): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN7Fortran7runtime2ioL11unitMapLockE'
unit.cpp:(.text._ZN7Fortran7runtime2ioL21CloseAllExternalUnitsEv+0x64): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN7Fortran7runtime2ioL7unitMapE'
unit.cpp:(.text._ZN7Fortran7runtime2ioL21CloseAllExternalUnitsEv+0x6b): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN7Fortran7runtime2ioL11unitMapLockE'
unit.cpp:(.text._ZN7Fortran7runtime2ioL21CloseAllExternalUnitsEv+0x71): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN7Fortran7runtime2ioL11unitMapLockE'
unit.cpp:(.text._ZN7Fortran7runtime2ioL21CloseAllExternalUnitsEv+0x86): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN7Fortran7runtime2ioL7unitMapE'
unit.cpp:(.text._ZN7Fortran7runtime2ioL21CloseAllExternalUnitsEv+0x92): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN7Fortran7runtime2ioL7unitMapE'
unit.cpp:(.text._ZN7Fortran7runtime2ioL21CloseAllExternalUnitsEv+0xa0): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN7Fortran7runtime2ioL13defaultOutputE'
unit.cpp:(.text._ZN7Fortran7runtime2ioL21CloseAllExternalUnitsEv+0xab): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN7Fortran7runtime2ioL12defaultInputE'
unit.cpp:(.text._ZN7Fortran7runtime2ioL21CloseAllExternalUnitsEv+0xb6): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN7Fortran7runtime2ioL11errorOutputE'
unit.cpp:(.text._ZN7Fortran7runtime2ioL21CloseAllExternalUnitsEv+0xc0): relocation truncated to fit: R_X86_64_PC32 against `.bss._ZN7Fortran7runtime2ioL11unitMapLockE'
/home/llvm-flang-src/install/lib/libFortranRuntime.a(unit.cpp.o): in function `Fortran::runtime::io::ExternalFileUnit::CreateUnitMap() [clone .localalias]':
unit.cpp:(.text._ZN7Fortran7runtime2io16ExternalFileUnit13CreateUnitMapEv+0x1e6): additional relocation overflows omitted from the output
flang-new: error: linker command failed with exit code 1 (use -v to see invocation)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUV01v4zYQ_TX0ZRBBHFtfBx8cJ0YLZNsgQYuil4CSRjZrmjTIkZP99wUlJessspe2BhofaEuPmnkz82w_qhD01hItRXYtspuZ6nnn_HKvvbJ7Ps5q136N2MYouxXZDdxpuycPndImCFxDrbdgXKMMKO_VV3jWvIPH1e-3oJi9rnumRKQ3Il2N60_kCXQA3hF4OnrX9g15MZ_gRjFc2RFJNlU63oX4kgD33m29OgBT4CczMDnbgLBWxkAQWAqszoB5XO69tgwCiwFGtxeIcRsWZzsXAGtnWWkbzu5m8NjX3vWsLX0QPh9WeCBlBJZ7bVuBpUzadAhfCVw_qhNBrHG-gpcIivlKpgJXAlf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