From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 68DA53858C83; Tue, 14 Mar 2023 12:15:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 68DA53858C83 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678796134; bh=Cga8gPZsy8AWiNU8q24lLo7HuyRsrGQ0Bh8J8e8ydo4=; h=From:To:Subject:Date:From; b=EehCoaaODXiHc3xEdg9B9g1df6i85AzenrFlhs5PLv0qM/qCRnJFRvuY3WGpXsEYV xtVyHtQ8E7yaXb9bgo5IT6WWKO23UnmRbHzH7nh5w0/NvG3Vgwqn/tfoZoq1MH6AR+ 3U6G9UYQLffpMEk3yg+yTuFKbWXvH/r2dGB49kEA= From: "burnus at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/109128] New: [Offload][OpenMP][OpenACC] Static linking with unused offload function will lead to mismatch number of offload fn/symbols Date: Tue, 14 Mar 2023 12:15:33 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: openacc, openmp, wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: burnus at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status keywords bug_severity priority component assigned_to reporter cc target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D109128 Bug ID: 109128 Summary: [Offload][OpenMP][OpenACC] Static linking with unused offload function will lead to mismatch number of offload fn/symbols Product: gcc Version: 13.0 Status: UNCONFIRMED Keywords: openacc, openmp, wrong-code Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org CC: jakub at gcc dot gnu.org Target Milestone: --- gfortran -fopenmp one.f90 ar rcv libone.a one.o ranlib libone.a gfortran -fopenmp two.f90 -L. -lone With GCN, it prints: libgomp: Cannot map target functions or variables (expected 0, have 2) The issue seems to be related to the linker removing the the symbol from __OFFLOAD_TABLE__ (i.e. from the .gnu.offload_funcs sections, which has first/last the__offload_func_table and __offload_funcs_end symbols, whose pointer is put into the __OFFLOAD_TABLE__). But the removed symbol is still visible to the offload compiler, i.e. it en= ds up in the GOMP_register_var call as generated by gcc/config/{gcn,nvptx}/mkoffload.cc It is not quite clear which permutations work or cause problems. It seems as if the common block (both files have then '.comm' sections) is important. Whether 'libone.a' also fails or only '-L. -lone' seems to be inconsistent (some minor details). Additionally, having a libgomp library c= all also in the main program is also required. =3D=3D> one.f90 <=3D=3D module m implicit none integer :: my_var common /my_common/ my_var contains integer function unused_func(n) result(res) integer :: n !$omp target map(from:res) firstprivate(n) res =3D 5*n !$omp end target end end module m =3D=3D> two.f90 <=3D=3D use m implicit none integer :: A !$omp target enter data map(A) end=