Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mkl random failed on CI machine #15791

Closed
dzhwinter opened this issue Feb 19, 2019 · 15 comments
Closed

mkl random failed on CI machine #15791

dzhwinter opened this issue Feb 19, 2019 · 15 comments
Assignees
Labels

Comments

@dzhwinter
Copy link
Contributor

dzhwinter commented Feb 19, 2019

[06:21:47] :	 [Step 1/1] 272/556 Test #242: test_eager_deletion_transformer .................***Failed  177.35 sec
[06:21:47] :	 [Step 1/1] 
[06:21:47] :	 [Step 1/1] W0219 06:19:48.812860 57169 device_context.cc:263] Please NOTE: device: 0, CUDA Capability: 61, Driver API Version: 9.0, Runtime API Version: 8.0
[06:21:47] :	 [Step 1/1] W0219 06:19:48.812909 57169 device_context.cc:271] device: 0, cuDNN Version: 7.0.
[06:21:47] :	 [Step 1/1] I0219 06:19:49.769515 57169 create_recordio_file_reader_op.cc:32] Creating file reader/tmp/eager_deletion_transformer.wmt16.recordio
[06:21:47] :	 [Step 1/1] [248.87572 210.63199] [154.26178 136.80447]
[06:21:47] :	 [Step 1/1] I0219 06:20:44.500957 57169 create_recordio_file_reader_op.cc:32] Creating file reader/tmp/eager_deletion_transformer.wmt16.recordio
[06:21:47] :	 [Step 1/1] I0219 06:20:44.949605 57169 build_strategy.cc:214] set enable_sequential_execution:1
[06:21:47] :	 [Step 1/1] [248.87572 210.63199] [154.26178 136.80447]
[06:21:47] :	 [Step 1/1] I0219 06:21:43.399361 57169 create_recordio_file_reader_op.cc:32] Creating file reader/tmp/eager_deletion_transformer.wmt16.recordio
[06:21:47] :	 [Step 1/1] *** Aborted at 1550557305 (unix time) try "date -d @1550557305" if you are using GNU date ***
[06:21:47] :	 [Step 1/1] PC: @                0x0 (unknown)
[06:21:47] :	 [Step 1/1] *** SIGSEGV (@0x1d0) received by PID 57169 (TID 0x7f3318627700) from PID 464; stack trace: ***
[06:21:47] :	 [Step 1/1]     @     0x7f3492304390 (unknown)
[06:21:47] :	 [Step 1/1]     @     0x7f3491f6281d getenv
[06:21:47] :	 [Step 1/1]     @     0x7f34275374a9 mkl_serv_getenv
[06:21:47] :	 [Step 1/1]     @     0x7f34277240e1 mkl_vml_kernel_ReadEnvVarMode
[06:21:47] :	 [Step 1/1]     @     0x7f3425fe6103 mkl_vml_kernel_GetMode
[06:21:47] :	 [Step 1/1]     @     0x7f3425fe6168 mkl_vml_kernel_GetTTableIndex
[06:21:47] :	 [Step 1/1]     @     0x7f3425d53dd3 vsAdd
[06:21:47] :	 [Step 1/1]     @     0x7f345aea80a0 paddle::operators::ElementwiseAddKernel<>::Compute()
[06:21:47] :	 [Step 1/1]     @     0x7f345aea874f _ZNSt17_Function_handlerIFvRKN6paddle9framework16ExecutionContextEEZNKS1_24OpKernelRegistrarFunctorINS0_8platform8CPUPlaceELb0ELm0EINS0_9operators20ElementwiseAddKernelINS7_16CPUDeviceContextEfEENSA_ISB_dEENSA_ISB_iEENSA_ISB_lEEEEclEPKcSI_iEUlS4_E_E9_M_invokeERKSt9_Any_dataS4_
[06:21:47] :	 [Step 1/1]     @     0x7f345b6b5ff7 paddle::framework::OperatorWithKernel::RunImpl()
[06:21:47] :	 [Step 1/1]     @     0x7f345b6afacd paddle::framework::OperatorBase::Run()
[06:21:47] :	 [Step 1/1]     @     0x7f345b4461d7 _ZNSt17_Function_handlerIFvvEZN6paddle9framework7details19ComputationOpHandle7RunImplEvEUlvE_E9_M_invokeERKSt9_Any_data
[06:21:47] :	 [Step 1/1]     @     0x7f345b43af61 paddle::framework::details::OpHandleBase::RunAndRecordEvent()
[06:21:47] :	 [Step 1/1]     @     0x7f345b446051 paddle::framework::details::ComputationOpHandle::RunImpl()
[06:21:47] :	 [Step 1/1]     @     0x7f345b43d0a1 paddle::framework::details::OpHandleBase::Run()
[06:21:47] :	 [Step 1/1]     @     0x7f345b3be9a5 _ZZN6paddle9framework7details24ThreadedSSAGraphExecutor5RunOpERKSt10shared_ptrINS0_13BlockingQueueIPNS1_13VarHandleBaseEEEEPNS1_12OpHandleBaseEENKUlvE_clEv
[06:21:47] :	 [Step 1/1]     @     0x7f345b3bf740 _ZNSt17_Function_handlerIFSt10unique_ptrINSt13__future_base12_Result_baseENS2_8_DeleterEEvENS1_12_Task_setterIS0_INS1_7_ResultIvEES3_ESt12_Bind_simpleIFSt17reference_wrapperISt5_BindIFZN6paddle9framework7details24ThreadedSSAGraphExecutor5RunOpERKSt10shared_ptrINSE_13BlockingQueueIPNSF_13VarHandleBaseEEEEPNSF_12OpHandleBaseEEUlvE_vEEEvEEvEEE9_M_invokeERKSt9_Any_data
[06:21:47] :	 [Step 1/1]     @     0x7f345a5ca82e std::__future_base::_State_baseV2::_M_do_set()
[06:21:47] :	 [Step 1/1]     @     0x7f3492301a99 __pthread_once_slow
[06:21:47] :	 [Step 1/1]     @     0x7f345b3bdfc7 _ZNSt13__future_base11_Task_stateISt5_BindIFZN6paddle9framework7details24ThreadedSSAGraphExecutor5RunOpERKSt10shared_ptrINS3_13BlockingQueueIPNS4_13VarHandleBaseEEEEPNS4_12OpHandleBaseEEUlvE_vEESaIiEFvvEE6_M_runEv
[06:21:47] :	 [Step 1/1]     @     0x7f345a5cbe84 _ZNSt6thread5_ImplISt12_Bind_simpleIFZN10ThreadPoolC4EmEUlvE_vEEE6_M_runEv
[06:21:47] :	 [Step 1/1]     @     0x7f3457c2fc80 (unknown)
[06:21:47] :	 [Step 1/1]     @     0x7f34922fa6ba start_thread
[06:21:47] :	 [Step 1/1]     @     0x7f349203041d clone
[06:21:47] :	 [Step 1/1]     @                0x0 (unknown)
[06:21:47] :	 [Step 1/1] Segmentation fault
[06:21:47] :	 [Step 1/1] 

see details in
http://ci.paddlepaddle.org/viewLog.html?buildId=60748&buildTypeId=Paddle_PrCi&tab=buildLog

@luotao1 luotao1 changed the title mkldnn random failed on CI machine mkl random failed on CI machine Feb 19, 2019
@luotao1 luotao1 added the Intel label Feb 19, 2019
@luotao1
Copy link
Contributor

luotao1 commented Feb 19, 2019

@yinghu5 @jianhang-liu Could you help see this issue?

@jianhang-liu
Copy link
Contributor

@luotao1 I had a check roughly and seems no issue in elementwise_add kernel itself. Since crash occur in BLAS, I will ask Hu Ying to check within MKL team also.

@jianhang-liu
Copy link
Contributor

As discussed in the meeting, we will wait for more reports with similar crash pattern and then re-start investigation.

@sneaxiy
Copy link
Collaborator

sneaxiy commented Aug 29, 2019

@luotao1 Hi, I found that mkl random failed on CI machine recently. See http://ci.paddlepaddle.org/viewLog.html?buildId=151271&buildTypeId=Paddle_PrCiCoverage&tab=buildLog. The error log is (please omit Signal raises logs):

0c13dda6c20b9e24ff62886f1a4c8af8

test_eager_deletion_transformer fails because of the above error. But since garbage collection strategy is opened by default since #18836, test_eager_deletion_transformer is the same as test_parallel_executor_transformer. I do not know why one of them fails and the other runs well. Please take a look.

@jianhang-liu
Copy link
Contributor

@yihuaxu Could you help to have a check? Thanks!

@yihuaxu
Copy link
Contributor

yihuaxu commented Aug 29, 2019

@yihuaxu Could you help to have a check? Thanks!

OK, I will discuss it with Hu Ying.

@luotao1
Copy link
Contributor

luotao1 commented Aug 30, 2019

@yihuaxu and @yinghu5 had investigated the problem, can’t reproduce the problem. But from symbols, it seems related to multi-processor or thread issues.
(parallelexcutor =4 , omp thread number =1)

# test_eager_deletion_transformer.py
os.environ['RECORDIO_FILENAME'] = './eager_deletion_transformer.wmt16.recordio' // 看这行
                                                                               
from test_parallel_executor_transformer import TestTransformer                
                                                                              
if __name__ == '__main__':                                                    
    unittest.main()                                                           

and

# test_parallel_executor_transformer.py
class TestTransformer(TestParallelExecutorBase):   
     @classmethod                                   
     def setUpClass(cls):                           
         os.environ['CPU_NUM'] = str(4)   // 看这行                                                              

I also discussed it with our developer team and get key confirmation: getenv() is not thread-safe if executed concurrently with setenv()
Please see the similar issue :
OpenBLAS : OpenMathLib/OpenBLAS#716
and mxnet environment : libc getenv is not threadsafe #13438

apache/mxnet#13438

It's hard for us to judge whether these environment sets might happen concurrently with vsAdd without a reproducer at hand.
but if they do -- these might be one of the reasons for a segfault. Could you please check those in details?
Then we may either try to workaround the problem by avoid them manually, either look for some solution by MKL internally.

image

@yihuaxu
Copy link
Contributor

yihuaxu commented Aug 30, 2019

Today I analyze the issue with the static method because I can not get the core dump file from the stress testing. Please refer to the below:
Status:
URL: #15791
Log:

[06:21:47] : [Step 1/1] *** Aborted at 1550557305 (unix time) try "date -d @1550557305" if you are using GNU date ***

[06:21:47] : [Step 1/1] PC: @ 0x0 (unknown)
[06:21:47] : [Step 1/1] *** SIGSEGV (@0x1D0) received by PID 57169 (TID 0x7f3318627700) from PID 464; stack trace: ***
[06:21:47] : [Step 1/1] @ 0x7f3492304390 (unknown)
[06:21:47] : [Step 1/1] @ 0x7f3491f6281d getenv
[06:21:47] : [Step 1/1] @ 0x7f34275374a9 mkl_serv_getenv
[06:21:47] : [Step 1/1] @ 0x7f34277240e1 mkl_vml_kernel_ReadEnvVarMode
[06:21:47] : [Step 1/1] @ 0x7f3425fe6103 mkl_vml_kernel_GetMode
[06:21:47] : [Step 1/1] @ 0x7f3425fe6168 mkl_vml_kernel_GetTTableIndex
[06:21:47] : [Step 1/1] @ 0x7f3425d53dd3 vsAdd
[06:21:47] : [Step 1/1] @ 0x7f345aea80a0 paddle::operators::ElementwiseAddKernel<>::Compute()
[06:21:47] : [Step 1/1] @ 0x7f345aea874f ZNSt17_Function_handlerIFvRKN6paddle9framework16ExecutionContextEEZNKS1_24OpKernelRegistrarFunctorINS0_8platform8CPUPlaceELb0ELm0EINS0_9operators20ElementwiseAddKernelINS7_16CPUDeviceContextEfEENSA_ISB_dEENSA_ISB_iEENSA_ISB_lEEEEclEPKcSI_iEUlS4_E_E9_M_invokeERKSt9_Any_dataS4
[06:21:47] : [Step 1/1] @ 0x7f345b6b5ff7 paddle::framework::OperatorWithKernel::RunImpl()
[06:21:47] : [Step 1/1] @ 0x7f345b6afacd paddle::framework::OperatorBase::Run()

       Offset: 0x7f3491f6281d - 0x7f3492304390 = 0x3A1B73

Analyze:

  1. Since the “getenv” function is the member of glibc, so we need check the parameters. And the “mkl_serv_getenv” function will get the “MKL_VML_DEBUG_CPU_TYPE” variable.

a. Use gdb to get the register value of r14.

       r14            0x7fff3fa92ea0   140734261440160

b. The variable name is “MKL_VML_DEBUG_CPU_TYPE”

      0x7fff3fa92ea0: "MKL_VML_DEBUG_CPU_TYPE"

c. assemble code.

libmklml_intel.so:

0000000001992790 <mkl_serv_getenv>:
1992790: 41 54 push %r12
1992792: 41 55 push %r13
1992794: 41 56 push %r14
<snip>
19928a0: c3 retq
19928a1: 4c 89 f7 mov %r14,%rdi
19928a4: e8 07 94 80 fe callq 19bcb0 getenv@plt
19928a9: 49 89 c7 mov %rax,%r15
19928ac: 4d 85 ff test %r15,%r15
<snip>

000000000019bcb0 getenv@plt:
19bcb0: ff 25 8a a7 a7 07 jmpq *0x7a7a78a(%rip) # 7c16440 <GLOBAL_OFFSET_TABLE+0x6ef0>
19bcb6: 68 db 0d 00 00 pushq $0xddb
19bcbb: e9 30 22 ff ff jmpq 18def0 <_init+0x28>

libc.so

0000000000039150 :
39150: 41 57 push %r15
39152: 41 56 push %r14
39154: 41 55 push %r13
39156: 41 54 push %r12
39158: 55 push %rbp
39159: 53 push %rbx
3915a: 48 89 fb mov %rdi,%rbx
3915d: 48 83 ec 08 sub $0x8,%rsp
39161: e8 ba 33 05 00 callq 8c520 <__GI_strlen>
39166: 49 89 c6 mov %rax,%r14
39169: 48 8b 05 28 cd 38 00 mov 0x38cd28(%rip),%rax # 3c5e98 <__environ@@GLIBC_2.2.5-0x35d0>
39170: 48 8b 28 mov (%rax),%rbp
39173: 48 85 ed test %rbp,%rbp
39176: 0f 84 ac 00 00 00 je 39228 <getenv+0xd8>
3917c: 0f b6 03 movzbl (%rbx),%eax
3917f: 84 c0 test %al,%al
39181: 0f 84 a1 00 00 00 je 39228 <getenv+0xd8>
39187: 80 7b 01 00 cmpb $0x0,0x1(%rbx)
3918b: 75 43 jne 391d0 <getenv+0x80>
3918d: 48 8b 5d 00 mov 0x0(%rbp),%rbx
39191: 80 cc 3d or $0x3d,%ah
39194: 48 85 db test %rbx,%rbx
39197: 75 14 jne 391ad <getenv+0x5d>
39199: eb 1b jmp 391b6 <getenv+0x66>
3919b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1)
391a0: 48 83 c5 08 add $0x8,%rbp
391a4: 48 8b 5d 00 mov 0x0(%rbp),%rbx
391a8: 48 85 db test %rbx,%rbx
391ab: 74 09 je 391b6 <getenv+0x66>
391ad: 66 3b 03 cmp (%rbx),%ax
391b0: 75 ee jne 391a0 <getenv+0x50>
391b2: 48 83 c3 02 add $0x2,%rbx
391b6: 48 83 c4 08 add $0x8,%rsp
391ba: 48 89 d8 mov %rbx,%rax
391bd: 5b pop %rbx
391be: 5d pop %rbp
391bf: 41 5c pop %r12
391c1: 41 5d pop %r13
391c3: 41 5e pop %r14
391c5: 41 5f pop %r15
391c7: c3 retq
391c8: 0f 1f 84 00 00 00 00 nopl 0x0(%rax,%rax,1)
391cf: 00
391d0: 44 0f b7 23 movzwl (%rbx),%r12d
391d4: 4c 8d 7b 02 lea 0x2(%rbx),%r15
391d8: 48 8b 5d 00 mov 0x0(%rbp),%rbx
391dc: 4d 8d 6e fe lea -0x2(%r14),%r13
391e0: 48 85 db test %rbx,%rbx
391e3: 75 18 jne 391fd <getenv+0xad>
391e5: eb cf jmp 391b6 <getenv+0x66>
391e7: 66 0f 1f 84 00 00 00 nopw 0x0(%rax,%rax,1)
391ee: 00 00
391f0: 48 83 c5 08 add $0x8,%rbp
391f4: 48 8b 5d 00 mov 0x0(%rbp),%rbx
391f8: 48 85 db test %rbx,%rbx
391fb: 74 b9 je 391b6 <getenv+0x66>
391fd: 66 44 3b 23 cmp (%rbx),%r12w
39201: 75 ed jne 391f0 <getenv+0xa0>
39203: 48 8d 7b 02 lea 0x2(%rbx),%rdi
39207: 4c 89 ea mov %r13,%rdx
3920a: 4c 89 fe mov %r15,%rsi
3920d: e8 0e 35 05 00 callq 8c720 <__GI_strncmp>
39212: 85 c0 test %eax,%eax
39214: 75 da jne 391f0 <getenv+0xa0>
39216: 42 80 3c 33 3d cmpb $0x3d,(%rbx,%r14,1)
3921b: 75 d3 jne 391f0 <getenv+0xa0>
3921d: 4a 8d 5c 33 01 lea 0x1(%rbx,%r14,1),%rbx
39222: eb 92 jmp 391b6 <getenv+0x66>
39224: 0f 1f 40 00 nopl 0x0(%rax)
39228: 31 db xor %ebx,%ebx
3922a: eb 8a jmp 391b6 <getenv+0x66>
3922c: 0f 1f 40 00 nopl 0x0(%rax)

  1. To analyze the assemble code of “getenv” can not find any abnormal invoking.
    a. Use gdb to get the loading information of libc.so

    0x00007ffff70ef310  0x00007ffff715a2d6  Yes (*)     /lib64/libm.so.6
    0x00007ffff6d3c930  0x00007ffff6e8bd2f  Yes (*)     /lib64/libc.so.6
    
    Offset: 0x00007ffff6e8bd2f  - 0x00007ffff6d3c930  = 0x14F3FF < 0x3A1B73
    

b. Since the environment issue is different from Baidu’s environment, The below is only to guess the crash point. But I can not find any invoking of “getenv“ function into ”libm.so.6“.
It need get the deep dive for it in future.

   0x7FFFF6D56150 + 0x3A1B73 = 0x7FFF F70F 7CC3 ==> libm.so.6
  1. Use the test utility to verify the “getenv” invoking.
    a. When set the parameters as “NULL”, it will crash at the instruction that named as “mov %rax,%r14”.
int main(void) {
char* s=NULL;
// s = getenv(“TEST”);
                   s = getenv(NULL); //It will crashed.
    printf("Command processor: %s\n",s); /* display comspec parameter */
    return 0;
}

b. When the environment name is set the long name, it can work normally.

image

image

@yinghu5
Copy link

yinghu5 commented Sep 4, 2019

following the thread https://rachelbythebay.com/w/2017/01/30/env/

we tried some workaround here.

  1. but first, could the parallel_executor of paddle do setenv before start sub thread?

""Really, you can't be sure who's going to be poking around in there. So all you can do is not call setenv. If for some reason you DO need to set up something in your environment for an eventually-multi-threaded program, you'd better get it out of the way before you kick off any threads, and then leave it like that forever. Don't try to change it while the program is running.

Incidentally, this is the same technique some programs use to fork with threads: they fork early before any threads are up. The parent continues on to start its threads, while that initial child then spawns everything else as needed (while being careful to not create threads itself).
"""

  1. for mkl sides, please try call dummy vsAdd() or
    unsigned int mod;
    mod = vmlGetMode( );
    prior any concurent executions so that Intel MKL sets up the internal state (read: calls getenv and cache the environment read). In this case in subsequent calls Intel MKL would not call mkl_vml_kenel_read_EnvVarmode() again and the problem should gone.

@sneaxiy
Copy link
Collaborator

sneaxiy commented Nov 5, 2019

@bingyanghuang The problem raises again, please see the log:
http://ci.paddlepaddle.org/viewLog.html?buildId=212598&buildTypeId=Paddle_PrCiCoverage&tab=buildLog

08f47815aaa167e8fb8aac3aeaadd274

@bingyanghuang
Copy link
Contributor

@yihuaxu Please help to see this issue.

@yihuaxu
Copy link
Contributor

yihuaxu commented Nov 5, 2019

@yihuaxu Please help to see this issue.

Could you provide the core dump files?@bingyanghuang @sneaxiy

@yinghu5
Copy link

yinghu5 commented Nov 15, 2019

Hi @yihuaxu @bingyanghuang

It is random failed and can't reproduce. what i can recommend may to try Intel inspector to see if it can disclose some problems even without reproduce the problem.

Here is https://software.intel.com/en-us/inspector
resolve Memory errors and nondeterministic threading errors, which are difficult to find without the right tool.

@paddle-bot-old
Copy link

Since you haven't replied for more than a year, we have closed this issue/pr.
If the problem is not solved or there is a follow-up one, please reopen it at any time and we will continue to follow up.
由于您超过一年未回复,我们将关闭这个issue/pr。
若问题未解决或有后续问题,请随时重新打开,我们会继续跟进。

@dynamicheart
Copy link
Contributor

dynamicheart commented Aug 19, 2024

一种可能的出错场景:
某个读线程在getenv遍历__environ表的过程中,其它线程调用了setenv设置了新的变量,导致环境变量表__environ被重新分配空间,并且环境变量表的起始指针__environ被修改,读线程在getenv用__environ在遍历中途变成一个invalid的内存区域,里面的数据可能会变成脏数据,对表项进行解引用时,会触发segmentation fault

关于setenv和getenv

以下为出错示例,在0x00007f41b7e50f4d <+173>处对(%r12)访问,引发segmentation fault

(gdb) disassemble
Dump of assembler code for function getenv:
   0x00007f41b7e50ea0 <+0>:	endbr64
   0x00007f41b7e50ea4 <+4>:	push   %r15
   0x00007f41b7e50ea6 <+6>:	push   %r14
   0x00007f41b7e50ea8 <+8>:	push   %r13
   0x00007f41b7e50eaa <+10>:	push   %r12
   0x00007f41b7e50eac <+12>:	push   %rbp
   0x00007f41b7e50ead <+13>:	push   %rbx
   0x00007f41b7e50eae <+14>:	sub    $0x8,%rsp
;   if (__environ == NULL || name[0] == '\0')
;     return NULL;
   0x00007f41b7e50eb2 <+18>:	mov    0x1a5ff7(%rip),%rax        ; 0x7f41b7ff6eb0
   0x00007f41b7e50eb9 <+25>:	mov    (%rax),%rbx
   0x00007f41b7e50ebc <+28>:	test   %rbx,%rbx
   0x00007f41b7e50ebf <+31>:	je     0x7f41b7e50f80 <getenv+224>
   0x00007f41b7e50ec5 <+37>:	movzbl (%rdi),%eax                    ; %rdi %r13 name
   0x00007f41b7e50ec8 <+40>:	mov    %rdi,%r13
   0x00007f41b7e50ecb <+43>:	test   %al,%al
   0x00007f41b7e50ecd <+45>:	je     0x7f41b7e50f80 <getenv+224>
;   if (name[1] == '\0')
;    {
;       name_start = ('=' << 8) | *(const unsigned char *) name;
   0x00007f41b7e50ed3 <+51>:	cmpb   $0x0,0x1(%rdi)
   0x00007f41b7e50ed7 <+55>:	mov    (%rbx),%r12                    ; %r12 __environ
   0x00007f41b7e50eda <+58>:	jne    0x7f41b7e50f20 <getenv+128>
   0x00007f41b7e50edc <+60>:	or     $0x3d,%ah                      ; %ax name_start
;         for (ep = __environ; *ep != NULL; ++ep)
;             {
;             uint16_t ep_start = (((unsigned char *) *ep)[0]
;                         | (((unsigned char *) *ep)[1] << 8));
;             if (name_start == ep_start)
;                 return &(*ep)[2];
;             }
;     }
   0x00007f41b7e50edf <+63>:	test   %r12,%r12
   0x00007f41b7e50ee2 <+66>:	jne    0x7f41b7e50efd <getenv+93>
   0x00007f41b7e50ee4 <+68>:	jmp    0x7f41b7e50f08 <getenv+104>
   0x00007f41b7e50ee6 <+70>:	nopw   %cs:0x0(%rax,%rax,1)
   0x00007f41b7e50ef0 <+80>:	mov    0x8(%rbx),%r12                ; %r12 *__ep
   0x00007f41b7e50ef4 <+84>:	add    $0x8,%rbx                     ; ++ep
   0x00007f41b7e50ef8 <+88>:	test   %r12,%r12
   0x00007f41b7e50efb <+91>:	je     0x7f41b7e50f08 <getenv+104>
   0x00007f41b7e50efd <+93>:	cmp    (%r12),%ax                    ; if (name_start == ep_start)
   0x00007f41b7e50f02 <+98>:	jne    0x7f41b7e50ef0 <getenv+80>
   0x00007f41b7e50f04 <+100>:	add    $0x2,%r12                     ; &(*ep)[2]
   0x00007f41b7e50f08 <+104>:	add    $0x8,%rsp
   0x00007f41b7e50f0c <+108>:	mov    %r12,%rax                     ; return value
   0x00007f41b7e50f0f <+111>:	pop    %rbx
   0x00007f41b7e50f10 <+112>:	pop    %rbp
   0x00007f41b7e50f11 <+113>:	pop    %r12
   0x00007f41b7e50f13 <+115>:	pop    %r13
   0x00007f41b7e50f15 <+117>:	pop    %r14
   0x00007f41b7e50f17 <+119>:	pop    %r15
   0x00007f41b7e50f19 <+121>:	ret
;     size_t len = strlen (name);
   0x00007f41b7e50f1a <+122>:	nopw   0x0(%rax,%rax,1)
   0x00007f41b7e50f20 <+128>:	call   0x7f41b7e2d460 <*ABS*+0x9f630@plt>
;     len -= 2;
;     name += 2;
   0x00007f41b7e50f25 <+133>:	add    $0x2,%r13                     ; %r13 name += 2
   0x00007f41b7e50f29 <+137>:	movzwl -0x2(%r13),%ebp               ; %ebp name[0]
   0x00007f41b7e50f2e <+142>:	mov    %rax,%r14                     ; %r14 len
   0x00007f41b7e50f31 <+145>:	lea    -0x2(%rax),%r15               ; %r15 len -= 2
;      for (ep = __environ; *ep != NULL; ++ep)
;	     {
   0x00007f41b7e50f35 <+149>:	test   %r12,%r12
   0x00007f41b7e50f38 <+152>:	jne    0x7f41b7e50f4d <getenv+173>
   0x00007f41b7e50f3a <+154>:	jmp    0x7f41b7e50f08 <getenv+104>
   0x00007f41b7e50f3c <+156>:	nopl   0x0(%rax)
   0x00007f41b7e50f40 <+160>:	mov    0x8(%rbx),%r12
   0x00007f41b7e50f44 <+164>:	add    $0x8,%rbx
   0x00007f41b7e50f48 <+168>:	test   %r12,%r12
   0x00007f41b7e50f4b <+171>:	je     0x7f41b7e50f08 <getenv+104>
;      if (name_start == ep_start && !strncmp (*ep + 2, name, len)
;          && (*ep)[len + 2] == '=')
;        return &(*ep)[len + 3];
=> 0x00007f41b7e50f4d <+173>:	cmp    (%r12),%bp                    ; name_start == ep_start
   0x00007f41b7e50f52 <+178>:	jne    0x7f41b7e50f40 <getenv+160>
   0x00007f41b7e50f54 <+180>:	lea    0x2(%r12),%rdi                ; *ep + 2
   0x00007f41b7e50f59 <+185>:	mov    %r15,%rdx                     ; name
   0x00007f41b7e50f5c <+188>:	mov    %r13,%rsi                     ; len
   0x00007f41b7e50f5f <+191>:	call   0x7f41b7e2d580 <*ABS*+0x9f710@plt>
   0x00007f41b7e50f64 <+196>:	test   %eax,%eax
   0x00007f41b7e50f66 <+198>:	jne    0x7f41b7e50f40 <getenv+160>
   0x00007f41b7e50f68 <+200>:	cmpb   $0x3d,(%r12,%r14,1)           ; (*ep)[len + 2] == '='
   0x00007f41b7e50f6d <+205>:	jne    0x7f41b7e50f40 <getenv+160>
   0x00007f41b7e50f6f <+207>:	lea    0x1(%r12,%r14,1),%r12         ; &(*ep)[len + 3]
   0x00007f41b7e50f74 <+212>:	jmp    0x7f41b7e50f08 <getenv+104>
   0x00007f41b7e50f76 <+214>:	nopw   %cs:0x0(%rax,%rax,1)
   0x00007f41b7e50f80 <+224>:	xor    %r12d,%r12d
   0x00007f41b7e50f83 <+227>:	jmp    0x7f41b7e50f08 <getenv+104>
End of assembler dump.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants