From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Subject: Re: [PATCH v7 2/2] tty: add rpmsg driver References: <20200324170407.16470-1-arnaud.pouliquen@st.com> <20200324170407.16470-3-arnaud.pouliquen@st.com> <1e4ce821-dd9b-bb04-774b-58a255834cf5@st.com> <54d9b379-ba51-b29c-db58-6e305773ee96@st.com> From: Jiri Slaby Message-ID: <7329d7bb-c9cd-8eb2-12c2-0b6d5cc2accf@suse.cz> Date: Thu, 26 Mar 2020 13:31:44 +0100 MIME-Version: 1.0 In-Reply-To: <54d9b379-ba51-b29c-db58-6e305773ee96@st.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit To: Arnaud POULIQUEN , Joe Perches , Ohad Ben-Cohen , Bjorn Andersson , Greg Kroah-Hartman , linux-kernel@vger.kernel.org, linux-remoteproc@vger.kernel.org, Mathieu Poirier Cc: Suman Anna , Fabien DESSENNE , linux-stm32@st-md-mailman.stormreply.com, xiang xiao List-ID: On 26. 03. 20, 11:59, Arnaud POULIQUEN wrote: > > > On 3/26/20 1:01 AM, Joe Perches wrote: >> On Wed, 2020-03-25 at 14:31 +0100, Jiri Slaby wrote: >>> The question was exactly about that: can a compiler optimize it to a >>> bare number or will strlen call remain there? >> >> $ cat str.c >> #include >> >> int foo(void) >> { >> return strlen("abc"); >> } >> >> $ gcc -c -O2 str.c >> $ objdump -d str.o >> str.o: file format elf64-x86-64 >> >> >> Disassembly of section .text: >> >> 0000000000000000 : >> 0: f3 0f 1e fa endbr64 >> 4: b8 03 00 00 00 mov $0x3,%eax >> 9: c3 retq >> >> > same result with arm gcc using -O1 or -Og: > > str.o: file format elf32-littlearm > > > Disassembly of section .text: > > 00000000 : > 0: e3a00003 mov r0, #3 > 4: e12fff1e bx lr > > So in conclusion replacing sizeof by srlen even if not optimized in -o0, right? Right, gcc guys just confirmed, that it's constant-folded during parsing already. I asked them as I tried to dump the tree.original and the constant was already there. So we are safe to use strlen, at least for gcc :P. Others should adapt if they don't follow. thanks, -- js suse labs