From owner-svn-src-all@freebsd.org Mon Jul 16 18:21:31 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id DBFCD1034215; Mon, 16 Jul 2018 18:21:30 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 91F677CCE2; Mon, 16 Jul 2018 18:21:30 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 5B93C202CB; Mon, 16 Jul 2018 18:21:30 +0000 (UTC) (envelope-from andrew@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w6GILUYs052750; Mon, 16 Jul 2018 18:21:30 GMT (envelope-from andrew@FreeBSD.org) Received: (from andrew@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w6GILULx052749; Mon, 16 Jul 2018 18:21:30 GMT (envelope-from andrew@FreeBSD.org) Message-Id: <201807161821.w6GILULx052749@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: andrew set sender to andrew@FreeBSD.org using -f From: Andrew Turner Date: Mon, 16 Jul 2018 18:21:30 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336349 - head/sys/sys X-SVN-Group: head X-SVN-Commit-Author: andrew X-SVN-Commit-Paths: head/sys/sys X-SVN-Commit-Revision: 336349 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Jul 2018 18:21:31 -0000 Author: andrew Date: Mon Jul 16 18:21:29 2018 New Revision: 336349 URL: https://svnweb.freebsd.org/changeset/base/336349 Log: Don't use the static keyword with DPCPU defines in arm64 modules. On arm64 compiler will create PC-relative loads and stores for static data. This means it doesn't emit a relocation. Unfortunately the in-kernel linker expects there to be one for DPCPU defines so it can modify its value so the code will use the correct DPCPU region. To workaround the lack of a relocation with static data remove it when building modules on arm64. The kernel is unaffected as it doesn't rely on modifying these relocations to find the data. PR: 225684 Reported by: Johannes Lundberg Reported by: Jose Luis Duran Reported by: Greg V Reviewed by: bz Sponsored by: ABT Systems Ltd Differential Revision: https://reviews.freebsd.org/D16145 Modified: head/sys/sys/pcpu.h Modified: head/sys/sys/pcpu.h ============================================================================== --- head/sys/sys/pcpu.h Mon Jul 16 15:39:33 2018 (r336348) +++ head/sys/sys/pcpu.h Mon Jul 16 18:21:29 2018 (r336349) @@ -84,8 +84,26 @@ extern uintptr_t dpcpu_off[]; /* struct _hack is to stop this from being used with the static keyword. */ #define DPCPU_DEFINE(t, n) \ struct _hack; t DPCPU_NAME(n) __section(DPCPU_SETNAME) __used +#if defined(KLD_MODULE) && defined(__aarch64__) +/* + * On some architectures the compiler will use PC-relative load to + * find the address of DPCPU data with the static keyword. We then + * use this to find the offset of the data in a per-CPU region. + * This works for in the kernel as we can allocate the space ahead + * of time, however modules need to allocate a sepatate space and + * then use relocations to fix the address of the data. As + * PC-relative data doesn't have a relocation there is nothing for + * the kernel module linker to fix so data is accessed from the + * wrong location. + * + * This is a workaround until a better solution can be found. +*/ #define DPCPU_DEFINE_STATIC(t, n) \ + t DPCPU_NAME(n) __section(DPCPU_SETNAME) __used +#else +#define DPCPU_DEFINE_STATIC(t, n) \ static t DPCPU_NAME(n) __section(DPCPU_SETNAME) __used +#endif /* * Accessors with a given base.