From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by dpdk.org (Postfix) with ESMTP id 51933255 for ; Sat, 31 Mar 2018 18:21:56 +0200 (CEST) Received: by mail-wm0-f66.google.com with SMTP id r131so20811686wmb.2 for ; Sat, 31 Mar 2018 09:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=aRf2VYHEs3vTv/t7Gsh9QOV9KxoAl+mPhATcng99ZY4=; b=C+cxhb8UQe1TW62Lt9R1z3MJJ89ebXdXenZ8D2F8HQIN38839tWOmjKROWEKsHnEzW XYUgNmkirX8yBl5E2iZKq7chYxNnUd4UULevI2kGsvBbPDTIzBdTFuVtcXCSZ1xM70Sq HDfTeaxMZ4QK9Q+VljAAAEGoj7LeZwAbshzHXiv0YcLoXO3GPA5fTpuQj/CKiyCZzltR ws1cuOMs+IiHnsJV98aB2DpmQYjD9d2f2eOX28unvH5Lru3BCB+8Hs6zTyZrzsIrRYRs ItYAXuvEja0mBqnFMxoiO4yqMguaZmKQakzfpwEIXNjE2uRoDSYZRvp+jGmf6Tpd6QK6 XyOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=aRf2VYHEs3vTv/t7Gsh9QOV9KxoAl+mPhATcng99ZY4=; b=srdKEc3u022tn23+2Qs31PQV77WpJ3/oaCugtMPXMySNFlHTHodDXnusNx0Ms2U97w D4yX9qKvsJ4kqhG5fV49SzVrql/VpcOxes9HwGiZ+lmfCTFoILnI2rGrUjD6743TFytI sVNlDohkHaQ0TsymhqP+2VXY2QS8TlEtbYe42gy7J+424pa6Wd4YWXcfbDHGuhkey/Ww kCq7D1F9Yt2TAp2V9gkMlc3gnsOxF5WASfiFcelWCw/5sOREqgTc9Ftg6xtueKW27L+1 /KUMCPJZ50fBnsYoakM13vJlTWABEaOn1ihKK01FZvHlivwZhnIcqOjz5ZdAf7vgq71S CE7Q== X-Gm-Message-State: ALQs6tAlzL+Zz02p9zl2jKlrxmtQ1YrN5O1Wpy9wU5VNwbSCXfFf18gs DPtG0Rlc/yzaxPyFEQdkySRJFg== X-Google-Smtp-Source: AIpwx496jXbO8j/ckVnlUoHzb6YX/TpjBvsm9pVVmYXQVdZJlhtHmsVNbTS5aFmG1N8FJT/ZaSUitA== X-Received: by 10.28.207.201 with SMTP id f192mr4863100wmg.148.1522513315766; Sat, 31 Mar 2018 09:21:55 -0700 (PDT) Received: from bidouze.vm.6wind.com (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id k184sm5154267wmk.45.2018.03.31.09.21.54 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sat, 31 Mar 2018 09:21:54 -0700 (PDT) Date: Sat, 31 Mar 2018 18:21:41 +0200 From: =?iso-8859-1?Q?Ga=EBtan?= Rivet To: Neil Horman Cc: Tonghao Zhang , Timothy Redaelli , Maxime Coquelin , Andrew Rybchenko , "dev@dpdk.org" , Ferruh Yigit , Thomas Monjalon Message-ID: <20180331162141.nmg6awzep53fgakz@bidouze.vm.6wind.com> References: <93d00a28-d52d-25b3-42d0-84b1d95c756a@redhat.com> <20180330162830.1d7ccba2@redhat.com> <20180331133342.GA31292@neilslaptop.think-freely.org> <20180331150947.5ob35sxk2iw4f4fq@bidouze.vm.6wind.com> <20180331152755.GA3261@neilslaptop.think-freely.org> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20180331152755.GA3261@neilslaptop.think-freely.org> User-Agent: NeoMutt/20170113 (1.7.2) Subject: Re: [dpdk-dev] Build is broken in dpdk-next-net X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 31 Mar 2018 16:21:56 -0000 On Sat, Mar 31, 2018 at 11:27:55AM -0400, Neil Horman wrote: > On Sat, Mar 31, 2018 at 05:09:47PM +0200, Gaëtan Rivet wrote: > > On Sat, Mar 31, 2018 at 09:33:43AM -0400, Neil Horman wrote: > > > On Fri, Mar 30, 2018 at 10:47:09PM +0800, Tonghao Zhang wrote: > > > > I rebuild it on ubuntu 17.10 and cash it. I use the 'RTE_SET_USED' to fix it. > > > > > > > > > > > > diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c > > > > index 771675718..f11803191 100644 > > > > --- a/lib/librte_vhost/fd_man.c > > > > +++ b/lib/librte_vhost/fd_man.c > > > > @@ -279,7 +279,8 @@ fdset_pipe_read_cb(int readfd, void *dat __rte_unused, > > > > int *remove __rte_unused) > > > > { > > > > char charbuf[16]; > > > > - read(readfd, charbuf, sizeof(charbuf)); > > > > + int r = read(readfd, charbuf, sizeof(charbuf)); > > > > + RTE_SET_USED(r); > > > > } > > > > > > > > void > > > > @@ -319,5 +320,6 @@ fdset_pipe_init(struct fdset *fdset) > > > > void > > > > fdset_pipe_notify(struct fdset *fdset) > > > > { > > > > - write(fdset->u.writefd, "1", 1); > > > > + int r = write(fdset->u.writefd, "1", 1); > > > > + RTE_SET_USED(r); > > > > } > > > > > > > > > > A better option might be to use _Pragma > > > > > > Something like this perhaps > > > > > > #define ALLOW_UNUSED(x) \ > > > _Pragma(push) \ > > > _Pragma(diagnostic ignored "-Wunused-result") \ > > > #x;\ > > > _Pragma(pop) > > > > > > This is of course untested, so it probably needs some tweaking, but this method > > > avoids the need to declare an additional stack variable, which i don't think can > > > be eliminated due to the cast. I believe that this method should also work > > > accross compilers (the gcc and clang compilers support this, and i think the > > > intel compiler should as well) > > > > > > Neil > > > > > > > It would be nice to avoid the definition of a useless variable. > > An alternative could be > > > > if (read() < 0) { > > /* Failure here is acceptable for such and such reason. */ > > } > > > > to ensure all-around compatibility, and the definition or another macro. > > Just a suggestion. > > > That would be a good alternative, but I think its effectiveness is dependent on > when the compiler does with the return value check. Without any code inside the > conditional, the compiler may optimize the check out, meaning the warning will > still be asserted. If it doesn't optimize the check out, then you have a > useless compare and jump instruction left in the code path. > > Best > Neil > I tested quickly, I see no difference with the three methods: #include __attribute__((warn_unused_result)) int wur(void) { return read(0, NULL, 0); } void with_void(void) { int ret; ret = wur(); (void) ret; } void with_pragma(void) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-result" wur(); #pragma GCC diagnostic pop } void with_if(void) { if (wur() < 0) { /* I do not care for errors. */ } } int main(void) { return 0; } ---------------------------- gcc -D_FORTIFY_SOURCE=2 -Wunused-result -Werror -O3 _wur.c -o wur_O3.out gcc -D_FORTIFY_SOURCE=2 -Wunused-result -Werror -O0 _wur.c -o wur_O0.out diff -Napy <(gdb -batch -ex 'file ./wur_O0.out' -ex 'disassemble with_void') <(gdb -batch -ex 'file ./wur_O3.out' -ex 'disassemble with_void') || true Dump of assembler code for function with_void: Dump of assembler code for function with_void: 0x00000000000006ca <+0>: push %rbp | 0x00000000000006e0 <+0>: xor %edx,%edx 0x00000000000006cb <+1>: mov %rsp,%rbp | 0x00000000000006e2 <+2>: xor %esi,%esi 0x00000000000006ce <+4>: sub $0x10,%rsp | 0x00000000000006e4 <+4>: xor %edi,%edi 0x00000000000006d2 <+8>: callq 0x6b0 | 0x00000000000006e6 <+6>: jmpq 0x560 0x00000000000006d7 <+13>: mov %eax,-0x4(%rbp) < 0x00000000000006da <+16>: nop < 0x00000000000006db <+17>: leaveq < 0x00000000000006dc <+18>: retq < End of assembler dump. End of assembler dump. diff -Napy <(gdb -batch -ex 'file ./wur_O0.out' -ex 'disassemble with_pragma') <(gdb -batch -ex 'file ./wur_O3.out' -ex 'disassemble with_pragma') || true Dump of assembler code for function with_pragma: Dump of assembler code for function with_pragma: 0x00000000000006dd <+0>: push %rbp | 0x00000000000006f0 <+0>: xor %edx,%edx 0x00000000000006de <+1>: mov %rsp,%rbp | 0x00000000000006f2 <+2>: xor %esi,%esi 0x00000000000006e1 <+4>: callq 0x6b0 | 0x00000000000006f4 <+4>: xor %edi,%edi 0x00000000000006e6 <+9>: nop | 0x00000000000006f6 <+6>: jmpq 0x560 0x00000000000006e7 <+10>: pop %rbp < 0x00000000000006e8 <+11>: retq < End of assembler dump. End of assembler dump. diff -Napy <(gdb -batch -ex 'file ./wur_O0.out' -ex 'disassemble with_if') <(gdb -batch -ex 'file ./wur_O3.out' -ex 'disassemble with_if') || true Dump of assembler code for function with_if: Dump of assembler code for function with_if: 0x00000000000006e9 <+0>: push %rbp | 0x0000000000000700 <+0>: xor %edx,%edx 0x00000000000006ea <+1>: mov %rsp,%rbp | 0x0000000000000702 <+2>: xor %esi,%esi 0x00000000000006ed <+4>: callq 0x6b0 | 0x0000000000000704 <+4>: xor %edi,%edi 0x00000000000006f2 <+9>: nop | 0x0000000000000706 <+6>: jmpq 0x560 0x00000000000006f3 <+10>: pop %rbp < 0x00000000000006f4 <+11>: retq < End of assembler dump. End of assembler dump. And then with __attribute__((warn_unused_result)) int wur(void) { return -1; } ----------------------------------- gcc -D_FORTIFY_SOURCE=2 -Wunused-result -Werror -O3 _wur.c -o wur_O3.out gcc -D_FORTIFY_SOURCE=2 -Wunused-result -Werror -O0 _wur.c -o wur_O0.out diff -Napy <(gdb -batch -ex 'file ./wur_O0.out' -ex 'disassemble with_void') <(gdb -batch -ex 'file ./wur_O3.out' -ex 'disassemble with_void') || true Dump of assembler code for function with_void: Dump of assembler code for function with_void: 0x000000000000066b <+0>: push %rbp | 0x0000000000000680 <+0>: repz retq 0x000000000000066c <+1>: mov %rsp,%rbp < 0x000000000000066f <+4>: sub $0x10,%rsp < 0x0000000000000673 <+8>: callq 0x660 < 0x0000000000000678 <+13>: mov %eax,-0x4(%rbp) < 0x000000000000067b <+16>: nop < 0x000000000000067c <+17>: leaveq < 0x000000000000067d <+18>: retq < End of assembler dump. End of assembler dump. diff -Napy <(gdb -batch -ex 'file ./wur_O0.out' -ex 'disassemble with_pragma') <(gdb -batch -ex 'file ./wur_O3.out' -ex 'disassemble with_pragma') || true Dump of assembler code for function with_pragma: Dump of assembler code for function with_pragma: 0x000000000000067e <+0>: push %rbp | 0x0000000000000690 <+0>: repz retq 0x000000000000067f <+1>: mov %rsp,%rbp < 0x0000000000000682 <+4>: callq 0x660 < 0x0000000000000687 <+9>: nop < 0x0000000000000688 <+10>: pop %rbp < 0x0000000000000689 <+11>: retq < End of assembler dump. End of assembler dump. diff -Napy <(gdb -batch -ex 'file ./wur_O0.out' -ex 'disassemble with_if') <(gdb -batch -ex 'file ./wur_O3.out' -ex 'disassemble with_if') || true Dump of assembler code for function with_if: Dump of assembler code for function with_if: 0x000000000000068a <+0>: push %rbp | 0x00000000000006a0 <+0>: repz retq 0x000000000000068b <+1>: mov %rsp,%rbp < 0x000000000000068e <+4>: callq 0x660 < 0x0000000000000693 <+9>: nop < 0x0000000000000694 <+10>: pop %rbp < 0x0000000000000695 <+11>: retq < End of assembler dump. End of assembler dump. There is a slight difference with the unoptimized version, otherwise any solution should work. We can also note that in -O3, having the additional variable on the stack makes no difference. -- Gaëtan Rivet 6WIND