On Mon, Jan 26, 2015 at 6:13 PM, Tim Hentenaar <[email protected]> wrote:
> Hi Denys,
>
> On Sun, Jan 25, 2015 at 09:58:50PM +0100, Denys Vlasenko wrote:
>> I don't understand why current code does not reach write_leases().
>> If tv.tv_sec is negative, we should not reach select() here -
>>
>> retval = 0;
>> if (!server_config.auto_time || tv.tv_sec > 0) {
>> retval = select(max_sock + 1, &rfds, NULL, NULL,
>> server_config.auto_time ? &tv :
>> NULL);
>> }
>> if (retval == 0) {
>> write_leases();
>> goto continue_with_autotime;
>> }
>>
>> and therefore, retval == 0 and we should reach write_leases().
>>
>> What am I missing?
>
> I wondered the same thing at first. Here's the relevent code as
> generated by GCC. Interestingly, the "tv_sec > 0" check seems to get
> optimized out (I'm compiling with -O2), and select() gets called as long
> as tv_sec is non-zero. Looks almost as if it's treating tv_sec as
> unsigned...
Can't be, "v > 0" is a valid test even for unsigned types.
>
> In my .config, I've got:
>
> CONFIG_EXTRA_CFLAGS="-O2 -fPIE -pie"
>
> Code generated with -O2:
> ; bb_common_bufsiz1+0x34 = server_config.auto_time -> %r15d
> 177d7: 44 8b 3d 96 ec 26 00 mov 0x26ec96(%rip),%r15d
> 177de: 89 c3 mov %eax,%ebx
> 177e0: 45 85 ff test %r15d,%r15d
> 177e3: 75 26 jne 1780b <udhcpd_main+0x30b>
>
> ; if (!server_config.auto_time) { select(...); }
> 177e5: 45 31 c0 xor %r8d,%r8d
> 177e8: 48 8b b5 60 fc ff ff mov -0x3a0(%rbp),%rsi
> 177ef: 8d 7b 01 lea 0x1(%rbx),%edi
> 177f2: 31 c9 xor %ecx,%ecx
> 177f4: 31 d2 xor %edx,%edx
> 177f6: e8 b5 08 ff ff callq 80b0 <select@plt>
Can you run "make networking/udhcp/dhcpd.s" and post the resulting file?
I'm seeing this code with gcc 4.3.1:
call udhcp_sp_fd_set #
movl %eax, %ebx #, max_sock
cmpl $0, bb_common_bufsiz1+44 #, <variable>.auto_time
je .L61 #,
call monotonic_sec #
movl 12(%esp), %edx # timeout_end,
subl %eax, %edx # D.7265,
movl %edx, 816(%esp) # tmp124, tv.tv_sec
movl $0, 820(%esp) #, tv.tv_usec
.L61:
xorl %eax, %eax # iftmp.50
cmpl $0, bb_common_bufsiz1+44 #, <variable>.auto_time
je .L63 #,
cmpl $0, 816(%esp) #, tv.tv_sec
jle .L64 #,
leal 816(%esp), %eax #, iftmp.50
.L63:
pushl %eax # iftmp.50
pushl $0 #
pushl $0 #
leal 664(%esp), %eax #, tmp125
pushl %eax # tmp125
leal 1(%ebx), %eax #, tmp126
pushl %eax # tmp126
call select #
addl $20, %esp #,
cmpl $0, %eax #, retval.323
jne .L65 #,
.L64:
call write_leases #
jmp .L102 #
.L65:
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox