develooper Front page | perl.perl5.porters | Postings from July 2016

[perl #128598] Quadmath builds fail porting/libperl.t

Thread Next
From:
Karl Williamson via RT
Date:
July 14, 2016 22:17
Subject:
[perl #128598] Quadmath builds fail porting/libperl.t
Message ID:
rt-4.0.18-19057-1468534666-69.128598-15-0@perl.org
On Sun Jul 10 21:52:17 2016, tonyc wrote:
> On Sun Jul 10 20:11:51 2016, dcollinsn@gmail.com wrote:
> > Greetings,
> >
> > If this is relevant, in the locale.o section of `nm libperl.a` I
> > found:
> >
> > 0000000000000000 t S_stdize_locale
> >                  U __stack_chk_fail
> >                  U stpcpy
> >                  U strchr
> >                  U strcmp
> >                  U strcpy
> >                  U strerror
> >                  U strlen
> >                  U strxfrm
> 
> I think it's optimizing this code:
> 
> *sans_nuls = '\0';
> 
> 
> /* Replace each NUL with the lowest collating control.  Loop until
> have
>  * exhausted all the NULs */
> while (s + s_strlen < e) {
>     strcat(sans_nuls, s);
> 
> /* Do the actual replacement */
> strcat(sans_nuls, PL_strxfrm_min_char);
> 
> /* Move past the input NUL */
> s += s_strlen + 1;
> s_strlen = strlen(s);
> }
> 
> At entry it can assume s points at the end of the string, and replaces
> strcat() with a call to stpcpy() (which is like strcpy(), but returns
> the address of the final NUL).  The second call to strcat() is then
> replaced with a call to strcpy(), using the result from stpcpy() as
> the destination:
> 
> movb    $0, (%rax)
> .LVL87:
> .loc 1 1585 0
> movq    24(%rsp), %rax
> .LVL88:
> addq    %rax, %r15
> .LVL89:
> cmpq    %r15, 16(%rsp)
> jbe     .L78
> movq    %rax, %r15
> .LVL90:
> .p2align 4,,10
> .p2align 3
> .L44:
> movq    %rbx, %rdi
> call    strlen
> .LVL91:
> leaq    (%rbx,%rax), %rdi
> .LBB134:
> .LBB135:
> .loc 2 142 0
> movq    %r15, %rsi
> .LBE135:
> .LBE134:
> .loc 1 1592 0
> leaq    1(%r15,%rbp), %r15
> .LVL92:
> .LBB137:
> .LBB136:
> .loc 2 142 0
> call    stpcpy
> .LVL93:
> .LBE136:
> .LBE137:
> .LBB138:
> .LBB139:
> movl    $PL_strxfrm_min_char, %esi
> movq    %rax, %rdi
> call    strcpy
> .LVL94:
> .LBE139:
> .LBE138:
> .loc 1 1593 0
> movq    %r15, %rdi
> call    strlen
> .LVL95:
> movq    %rax, %rbp
> .LVL96:
> .loc 1 1585 0
> leaq    (%r15,%rax), %rax
> .LVL97:
> cmpq    %rax, 16(%rsp)
> ja      .L44
> jmp     .L43
> 
> Building with optimization disabled removes the reference to strcpy().
> 
> Tony

It seems to me the best course would be to disable this test if optimization is being done.  The point is to catch places in the code where a programmer has made a mistake, and is using unsafe C paradigms. One generally assumes that the optimizer knows what it is doing, and we don't have to check up on it. By skipping the test on optimized builds, we still will get an indication in our smokes that the programmer made a potential mistake, so that is adequate for our purpose.
-- 
Karl Williamson

---
via perlbug:  queue: perl5 status: open
https://rt.perl.org/Ticket/Display.html?id=128598

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About