Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1895561imu; Sat, 10 Nov 2018 03:58:46 -0800 (PST) X-Google-Smtp-Source: AJdET5fnh7YnHGEqIMqETp3o1rz7FStEanJkv4NW1AEUp+YR9mCZbUA72ToajMJlPg93hHxjvjsE X-Received: by 2002:aa7:858b:: with SMTP id w11-v6mr13060293pfn.77.1541851126000; Sat, 10 Nov 2018 03:58:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541851125; cv=none; d=google.com; s=arc-20160816; b=rmhI9nh2N5BpR5yRrvqD8poT/WCpceOXhkAAPrhmW71MoFvxH7kWFryFwefMLmeXEz REfphe9LNztMIIYweY55T6htQlQWCUhkkJjb1EbO3s8lN7Y7I9+G2jXv0xrQQiNNipGU m0Ivnn/hQlf5BOMEYDpJtWAmuBuorGwMSK7IehGLEJ0WGxHzpFN92FPdi3/pbn9glRpG vk2PB+DuJR1vxwRBFeKOasft+sY942QiOuJmYGly2C4BjYs59Z0QEG5gFIUpNlUPLj1c eOGBdGhNF7ptA0tmUU4mJ4ob4Wk1bM+1xFptCE/hh4BOzIHgBzIdcHoe23ngfGCjtsYF mhOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:references:in-reply-to:mime-version :dkim-signature; bh=P1V5x2k7fOoJ8xXi2CY9WNnfD740a6H/HHDON62o4xE=; b=aROCKaWT/wgW5yIf2oHuKQ/EIXPJHa2iAAkvx+08ItPK0nQgbY0sDg3KPyvneOqHp0 4V39rb+/ZjcJ09vJ9QCx0nAQQ6/xy+DknUKBMtU7zjC4ei+dajRQ5/aVHxefzyaIM+fc 61AIRo0jm9FtNlSOhBhwwh0IDwTRYsNGO+w7mqPvOMzn93YJhB8CgXjnHy+ImfGFbHru cUMFKOaLuuAkH+i3UtT84mKvpiqMhPJRO4qTWb8CSJ9vDXk+oMhAitdnDBTMyoWCxQk1 SEs/0HOx/T3IvNFJLEYiGERaj0MwLSJX63YXPbQfaABsYM9rXsVhYFLZ9oUgjCDYfD3I jmBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZjBKGYsA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b59-v6si12860628plb.206.2018.11.10.03.58.30; Sat, 10 Nov 2018 03:58:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZjBKGYsA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729066AbeKJVm4 (ORCPT + 99 others); Sat, 10 Nov 2018 16:42:56 -0500 Received: from mail-it1-f194.google.com ([209.85.166.194]:56136 "EHLO mail-it1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728959AbeKJVm4 (ORCPT ); Sat, 10 Nov 2018 16:42:56 -0500 Received: by mail-it1-f194.google.com with SMTP id b7-v6so6642984itd.5 for ; Sat, 10 Nov 2018 03:58:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=P1V5x2k7fOoJ8xXi2CY9WNnfD740a6H/HHDON62o4xE=; b=ZjBKGYsApAdYoLBZGneYf8hLXYVD+djsMckoOT6nBhllFDbT2CtTgvSgS5SBe4RGWs 90s3Oh9GXikww0mBKKQFCkXnMDnf1sdAt7tzvyKhJTc9r/saF5RAMMfHb+V45Jk1pbEb nu56v3ihzYK/LY6LuV4NH0dmW+qbInZxrcKl0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=P1V5x2k7fOoJ8xXi2CY9WNnfD740a6H/HHDON62o4xE=; b=dfDZzm9s20AVVBL913BZVFeNacJydZ29/zOj7sgk9tBFyttXOhadR2C6qJub+XVqA1 4/A8ZyyoVuWtkvZK1EfngPeIrGSVoDm8ceWWSAjb2j3CUQaOGE2ChOCaoKakVC+M7yra 6gBE5c8S79U8GQD2SZkTpjhYGoaFyItUGdOFDuTj/w18uk9Dn/AJ9PFyRMeZcvNfCRQM sKLFHZNJMC7git1shZD9FCmKAjFk/a69r8o9hApOxo5bQw+F+YyEOax0At2k02W/Kl8q xLttrUNDh64+s1E6RlMY3au0bzHVk0wCk97b4npOA/NaIzguq+9NRA6bGs3IAbUmnm5o lRKg== X-Gm-Message-State: AGRZ1gJDgEUb/tZWSIqTWbN9YGULwOQ1LlmckuPat+KucyZEEGOlQ93R nc2Xxs0ER3BwX5afzyW5OMf9UCyiUgQYXuA6bPX9fQ== X-Received: by 2002:a24:2190:: with SMTP id e138-v6mr5640235ita.71.1541851088798; Sat, 10 Nov 2018 03:58:08 -0800 (PST) MIME-Version: 1.0 Received: by 2002:a6b:4f16:0:0:0:0:0 with HTTP; Sat, 10 Nov 2018 03:58:08 -0800 (PST) In-Reply-To: <20181110001023.57f27312@vmware.local.home> References: <3cf04e113d71c9f8e4be95fb84a510f085aa4afa.1541711457.git.jpoimboe@redhat.com> <20181109133337.63487e3a@gandalf.local.home> <20181109193505.5p5iddrtgpk2cpb4@treble> <20181109145746.0037da3f@gandalf.local.home> <20181109203459.wbftlkxcvfnwo2bm@treble> <20181110001023.57f27312@vmware.local.home> From: Ard Biesheuvel Date: Sat, 10 Nov 2018 12:58:08 +0100 Message-ID: Subject: Re: [RFC PATCH 1/3] static_call: Add static call infrastructure To: Steven Rostedt Cc: Josh Poimboeuf , Linux Kernel Mailing List , "the arch/x86 maintainers" , Andy Lutomirski , Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Linus Torvalds , Masami Hiramatsu , Jason Baron , Jiri Kosina , David Laight , Borislav Petkov Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10 November 2018 at 06:10, Steven Rostedt wrote: > On Fri, 9 Nov 2018 14:34:59 -0600 > Josh Poimboeuf wrote: > > I'm slowly massaging this to work with tracepoints. > > But I hit a snag on this patch. > >> On Fri, Nov 09, 2018 at 02:57:46PM -0500, Steven Rostedt wrote: >> > On Fri, 9 Nov 2018 13:35:05 -0600 >> > Josh Poimboeuf wrote: >> > >> > >> > > > > +#define DECLARE_STATIC_CALL(key, func) = \ >> > > > > + extern struct static_call_key key; = \ >> > > > > + extern typeof(func) STATIC_CALL_TRAMP(key); = \ >> > > > > + /* Preserve the ELF symbol so objtool can access it: */ = \ >> > > > > + __ADDRESSABLE(key) >> > > > >> > > > Does the __ADDRESSABLE(key) need to be in the DECLARE part? >> > > > If so, there needs to be more explanation than just the comment ab= ove >> > > > it. >> > > >> > > For each call site, objtool creates a struct in .static_call_sites: >> > > >> > > struct static_call_site { >> > > s32 addr; >> > > s32 key; >> > > }; >> > > >> > > In order to do that, it needs to create a relocation which reference= s >> > > the key symbol. If the key is defined in another .o file, then the >> > > current .o will not have an ELF symbol associated with the key. The >> > > __ADDRESSABLE(key) thing tells GCC to leave the key symbol in the .o >> > > file, even though it's not referenced anywhere. That makes objtool'= s >> > > job easier, so it doesn't have to edit the symbol table. >> > > >> > > I could add a comment saying as much, though it's hard to explain it= in >> > > fewer words than I just did :-) >> > >> > Does this have to do with adding the references by relative address? >> > >> > In record_mcount, I just picked an existing symbol and referenced that= .. >> > But perhaps this is a cleaner way. >> >> I think recordmcount is different. It creates references (in >> __mcount_loc) to functions which are already in the object file, so they >> already have symbols associated with them. >> >> But in this case, when objtool is creating references, the symbol it >> needs to reference is outside the .o file, so there's no symbol to >> associate it with. >> > > The __ADDRESSABLE() appears to fail if you have a header with a > DECLARE_STATIC_CALL() that is included where the DEFINE_STATIC_CALL() > is, because I'm getting this: > > In file included from : > /work/git/linux-trace.git/include/linux/compiler.h:285:11: error: redefin= ition of =E2=80=98__addressable___tp_func_sys_enter40=E2=80=99 > __PASTE(__addressable_##sym, __LINE__) =3D (void *)&sym; > ^~~~~~~~~~~~~~ > /work/git/linux-trace.git/include/linux/compiler_types.h:53:23: note: in = definition of macro =E2=80=98___PASTE=E2=80=99 > #define ___PASTE(a,b) a##b > ^ > /work/git/linux-trace.git/include/linux/compiler.h:285:3: note: in expans= ion of macro =E2=80=98__PASTE=E2=80=99 > __PASTE(__addressable_##sym, __LINE__) =3D (void *)&sym; > ^~~~~~~ > /work/git/linux-trace.git/include/linux/static_call.h:112:2: note: in exp= ansion of macro =E2=80=98__ADDRESSABLE=E2=80=99 > __ADDRESSABLE(key) > ^~~~~~~~~~~~~ > /work/git/linux-trace.git/include/linux/static_call.h:115:2: note: in exp= ansion of macro =E2=80=98DECLARE_STATIC_CALL=E2=80=99 > DECLARE_STATIC_CALL(key, _func); \ > ^~~~~~~~~~~~~~~~~~~ > /work/git/linux-trace.git/include/linux/tracepoint.h:310:2: note: in expa= nsion of macro =E2=80=98DEFINE_STATIC_CALL=E2=80=99 > DEFINE_STATIC_CALL(__tp_func_##name, __tracepoint_iter_##name); > ^~~~~~~~~~~~~~~~~~ > /work/git/linux-trace.git/include/trace/define_trace.h:42:2: note: in exp= ansion of macro =E2=80=98DEFINE_TRACE_FN=E2=80=99 > DEFINE_TRACE_FN(name, reg, unreg, PARAMS(proto), PARAMS(args)) > ^~~~~~~~~~~~~~~ > /work/git/linux-trace.git/include/trace/events/syscalls.h:18:1: note: in = expansion of macro =E2=80=98TRACE_EVENT_FN=E2=80=99 > TRACE_EVENT_FN(sys_enter, > ^~~~~~~~~~~~~~ > /work/git/linux-trace.git/include/linux/compiler.h:285:11: note: previous= definition of =E2=80=98__addressable___tp_func_sys_enter40=E2=80=99 was he= re > __PASTE(__addressable_##sym, __LINE__) =3D (void *)&sym; > ^~~~~~~~~~~~~~ > /work/git/linux-trace.git/include/linux/compiler_types.h:53:23: note: in = definition of macro =E2=80=98___PASTE=E2=80=99 > #define ___PASTE(a,b) a##b > ^ > /work/git/linux-trace.git/include/linux/compiler.h:285:3: note: in expans= ion of macro =E2=80=98__PASTE=E2=80=99 > __PASTE(__addressable_##sym, __LINE__) =3D (void *)&sym; > ^~~~~~~ > /work/git/linux-trace.git/include/linux/static_call.h:112:2: note: in exp= ansion of macro =E2=80=98__ADDRESSABLE=E2=80=99 > __ADDRESSABLE(key) > ^~~~~~~~~~~~~ > /work/git/linux-trace.git/include/linux/tracepoint.h:234:2: note: in expa= nsion of macro =E2=80=98DECLARE_STATIC_CALL=E2=80=99 > DECLARE_STATIC_CALL(__tp_func_##name, __tracepoint_iter_##name); \ > ^~~~~~~~~~~~~~~~~~~ > /work/git/linux-trace.git/include/linux/tracepoint.h:421:2: note: in expa= nsion of macro =E2=80=98__DECLARE_TRACE=E2=80=99 > __DECLARE_TRACE(name, PARAMS(proto), PARAMS(args), \ > ^~~~~~~~~~~~~~~ > /work/git/linux-trace.git/include/linux/tracepoint.h:560:2: note: in expa= nsion of macro =E2=80=98DECLARE_TRACE=E2=80=99 > DECLARE_TRACE(name, PARAMS(proto), PARAMS(args)) > ^~~~~~~~~~~~~ > /work/git/linux-trace.git/include/trace/events/syscalls.h:18:1: note: in = expansion of macro =E2=80=98TRACE_EVENT_FN=E2=80=99 > TRACE_EVENT_FN(sys_enter, > > The complaint is on: > > DEFINE_STATIC_CALL(__tp_func_##name, __tracepoint_iter_##name); > > And the previous definition is on: > > DECLARE_STATIC_CALL(__tp_func_##name, __tracepoint_iter_##name); = \ > Does the DECLARE really need the __ADDRESSABLE? Its purpose is to ensure that symbols with static linkage are not optimized away, but since the reference is from a header file, the symbol should have external linkage anyway.