diff mbox

[edk2,RFC] OvmfPkg: reproducer for gcc-4.8's -Os causing corruption on X64

Message ID 1415192483-20009-1-git-send-email-lersek@redhat.com
State New
Headers show

Commit Message

Laszlo Ersek Nov. 5, 2014, 1:01 p.m. UTC
Build:

  . edksetup.sh
  make -C "$EDK_TOOLS_PATH"
  nice build -p OvmfPkg/OvmfPkgX64.dsc -b DEBUG -t GCC48 -a X64 \
    -n $(getconf _NPROCESSORS_ONLN)

Run:

  cp Build/OvmfX64/DEBUG_GCC48/FV/OVMF_VARS.fd vars.fd

  qemu-system-x86_64 \
    -nodefaults \
    -nodefconfig \
    -nographic \
    \
    -m 1024 \
    -enable-kvm \
    -M pc \
    \
    -drive if=pflash,format=raw,file=Build/OvmfX64/DEBUG_GCC48/FV/OVMF_CODE.fd,readonly \
    -drive if=pflash,format=raw,file=vars.fd \
    \
    -chardev stdio,signal=off,mux=on,id=char0 \
    -mon chardev=char0,mode=readline,default \
    -serial chardev:char0 \
    \
    -chardev file,id=char1,path=ovmf.debug.log \
    -device isa-debugcon,iobase=0x402,chardev=char1 \
    \
    -drive file=fat:Build/OvmfX64/DEBUG_GCC48/X64,id=drive0,if=none,format=raw \
    -device virtio-blk-pci,drive=drive0

  Shell> GccBugReproducer-O0
  0x00 0x01 0x02 0x03
  0x04 0x05 0x06 0x07
  0x08 0x09 0x0A 0x0B
  0x0C 0x0D 0x0E 0x0F
  0x10 0x11 0x12 0x13
  0x14 0x15 0x16 0x17
  0x18 0x19 0x1A 0x1B
  0x1C 0x1D 0x1E 0x00

  Shell> GccBugReproducer-Os
  0x3F443E4000 0x3E95894E00 0x3EB0001800 0x3FF686C000
  0x3F443E4000 0x3E95894E00 0x3EB0001800 0x3FF686C000

  Shell> reset -s

Disassembly of the -O0 case (with 'objdump -S
Build/OvmfX64/DEBUG_GCC48/X64/OvmfPkg/GccBugReproducer/GccBugReproducer-O0/OUTPUT/GccBugReproducer.obj'):

>
> Build/OvmfX64/DEBUG_GCC48/X64/OvmfPkg/GccBugReproducer/GccBugReproducer-O0/OUTPUT/GccBugReproducer.obj:     file format elf64-x86-64
>
>
> Disassembly of section .text.Print4:
>
> 0000000000000000 <Print4>:
>   IN UINT64  Dummy2,
>   IN UINT64  Dummy3,
>   IN BOOLEAN Recursive,
>   IN VA_LIST Marker
>   )
> {
>    0:	55                   	push   %rbp
>    1:	48 89 e5             	mov    %rsp,%rbp
>    4:	48 83 ec 60          	sub    $0x60,%rsp
>    8:	48 89 4d 10          	mov    %rcx,0x10(%rbp)
>    c:	48 89 55 18          	mov    %rdx,0x18(%rbp)
>   10:	4c 89 45 20          	mov    %r8,0x20(%rbp)
>   14:	44 89 c8             	mov    %r9d,%eax
>   17:	88 45 28             	mov    %al,0x28(%rbp)
>   UINT64 Value1, Value2, Value3, Value4;
>
>   do {
>     Value1 = VA_ARG (Marker, UINT64);
>   1a:	48 83 45 30 08       	addq   $0x8,0x30(%rbp)
>   1f:	48 8b 45 30          	mov    0x30(%rbp),%rax
>   23:	48 8b 40 f8          	mov    -0x8(%rax),%rax
>   27:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
>     Value2 = VA_ARG (Marker, UINT64);
>   2b:	48 83 45 30 08       	addq   $0x8,0x30(%rbp)
>   30:	48 8b 45 30          	mov    0x30(%rbp),%rax
>   34:	48 8b 40 f8          	mov    -0x8(%rax),%rax
>   38:	48 89 45 f0          	mov    %rax,-0x10(%rbp)
>     Value3 = VA_ARG (Marker, UINT64);
>   3c:	48 83 45 30 08       	addq   $0x8,0x30(%rbp)
>   41:	48 8b 45 30          	mov    0x30(%rbp),%rax
>   45:	48 8b 40 f8          	mov    -0x8(%rax),%rax
>   49:	48 89 45 e8          	mov    %rax,-0x18(%rbp)
>     Value4 = VA_ARG (Marker, UINT64);
>   4d:	48 83 45 30 08       	addq   $0x8,0x30(%rbp)
>   52:	48 8b 45 30          	mov    0x30(%rbp),%rax
>   56:	48 8b 40 f8          	mov    -0x8(%rax),%rax
>   5a:	48 89 45 e0          	mov    %rax,-0x20(%rbp)
>
>     if (!Recursive) {
>   5e:	80 7d 28 00          	cmpb   $0x0,0x28(%rbp)
>   62:	75 36                	jne    9a <Print4+0x9a>
>       AsciiPrint ("0x%02Lx 0x%02Lx 0x%02Lx 0x%02Lx\n",
>   64:	4c 8b 45 e8          	mov    -0x18(%rbp),%r8
>   68:	48 8b 4d f0          	mov    -0x10(%rbp),%rcx
>   6c:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
>   70:	48 8b 55 e0          	mov    -0x20(%rbp),%rdx
>   74:	48 89 54 24 20       	mov    %rdx,0x20(%rsp)
>   79:	4d 89 c1             	mov    %r8,%r9
>   7c:	49 89 c8             	mov    %rcx,%r8
>   7f:	48 89 c2             	mov    %rax,%rdx
>   82:	48 b9 00 00 00 00 00 	movabs $0x0,%rcx
>   89:	00 00 00
>   8c:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>   93:	00 00 00
>   96:	ff d0                	callq  *%rax
>         Value1, Value2, Value3, Value4);
>       return;
>   98:	eb 53                	jmp    ed <Print4+0xed>
>     }
>     PrintSeveralQuadruplets (Dummy1, Dummy2, Dummy3, FALSE,
>   9a:	48 8b 4d 20          	mov    0x20(%rbp),%rcx
>   9e:	48 8b 45 18          	mov    0x18(%rbp),%rax
>   a2:	48 8b 55 e0          	mov    -0x20(%rbp),%rdx
>   a6:	48 89 54 24 38       	mov    %rdx,0x38(%rsp)
>   ab:	48 8b 55 e8          	mov    -0x18(%rbp),%rdx
>   af:	48 89 54 24 30       	mov    %rdx,0x30(%rsp)
>   b4:	48 8b 55 f0          	mov    -0x10(%rbp),%rdx
>   b8:	48 89 54 24 28       	mov    %rdx,0x28(%rsp)
>   bd:	48 8b 55 f8          	mov    -0x8(%rbp),%rdx
>   c1:	48 89 54 24 20       	mov    %rdx,0x20(%rsp)
>   c6:	41 b9 00 00 00 00    	mov    $0x0,%r9d
>   cc:	49 89 c8             	mov    %rcx,%r8
>   cf:	48 89 c2             	mov    %rax,%rdx
>   d2:	48 8b 4d 10          	mov    0x10(%rbp),%rcx
>   d6:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>   dd:	00 00 00
>   e0:	ff d0                	callq  *%rax
>       Value1, Value2, Value3, Value4);
>   } while (Value4 != 0);
>   e2:	48 83 7d e0 00       	cmpq   $0x0,-0x20(%rbp)
>   e7:	0f 85 2d ff ff ff    	jne    1a <Print4+0x1a>
> }
>   ed:	c9                   	leaveq
>   ee:	c3                   	retq
>
> Disassembly of section .text.PrintSeveralQuadruplets:
>
> 0000000000000000 <PrintSeveralQuadruplets>:
>   IN UINT64  Dummy2,
>   IN UINT64  Dummy3,
>   IN BOOLEAN Recursive,
>   ...
>   )
> {
>    0:	55                   	push   %rbp
>    1:	48 89 e5             	mov    %rsp,%rbp
>    4:	48 83 ec 40          	sub    $0x40,%rsp
>    8:	48 89 4d 10          	mov    %rcx,0x10(%rbp)
>    c:	48 89 55 18          	mov    %rdx,0x18(%rbp)
>   10:	4c 89 45 20          	mov    %r8,0x20(%rbp)
>   14:	44 89 c8             	mov    %r9d,%eax
>   17:	88 45 28             	mov    %al,0x28(%rbp)
>   VA_LIST Marker;
>
>   VA_START (Marker, Recursive);
>   1a:	48 8d 45 28          	lea    0x28(%rbp),%rax
>   1e:	48 83 c0 08          	add    $0x8,%rax
>   22:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
>   Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>   26:	0f b6 45 28          	movzbl 0x28(%rbp),%eax
>   2a:	44 0f b6 c0          	movzbl %al,%r8d
>   2e:	48 8b 45 20          	mov    0x20(%rbp),%rax
>   32:	4c 8d 50 03          	lea    0x3(%rax),%r10
>   36:	48 8b 45 18          	mov    0x18(%rbp),%rax
>   3a:	48 8d 50 02          	lea    0x2(%rax),%rdx
>   3e:	48 8b 45 10          	mov    0x10(%rbp),%rax
>   42:	48 8d 48 01          	lea    0x1(%rax),%rcx
>   46:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
>   4a:	48 89 44 24 20       	mov    %rax,0x20(%rsp)
>   4f:	45 89 c1             	mov    %r8d,%r9d
>   52:	4d 89 d0             	mov    %r10,%r8
>   55:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>   5c:	00 00 00
>   5f:	ff d0                	callq  *%rax
>   VA_END (Marker);
>   61:	48 c7 45 f8 00 00 00 	movq   $0x0,-0x8(%rbp)
>   68:	00
> }
>   69:	c9                   	leaveq
>   6a:	c3                   	retq
>
> Disassembly of section .text.ShellAppMain:
>
> 0000000000000000 <ShellAppMain>:
> EFIAPI
> ShellAppMain (
>   IN UINTN Argc,
>   IN CHAR16 **Argv
>   )
> {
>    0:	55                   	push   %rbp
>    1:	48 89 e5             	mov    %rsp,%rbp
>    4:	48 81 ec 20 01 00 00 	sub    $0x120,%rsp
>    b:	48 89 4d 10          	mov    %rcx,0x10(%rbp)
>    f:	48 89 55 18          	mov    %rdx,0x18(%rbp)
>   PrintSeveralQuadruplets (0, 0, 0, TRUE,
>   13:	48 c7 84 24 18 01 00 	movq   $0x0,0x118(%rsp)
>   1a:	00 00 00 00 00
>   1f:	48 c7 84 24 10 01 00 	movq   $0x1e,0x110(%rsp)
>   26:	00 1e 00 00 00
>   2b:	48 c7 84 24 08 01 00 	movq   $0x1d,0x108(%rsp)
>   32:	00 1d 00 00 00
>   37:	48 c7 84 24 00 01 00 	movq   $0x1c,0x100(%rsp)
>   3e:	00 1c 00 00 00
>   43:	48 c7 84 24 f8 00 00 	movq   $0x1b,0xf8(%rsp)
>   4a:	00 1b 00 00 00
>   4f:	48 c7 84 24 f0 00 00 	movq   $0x1a,0xf0(%rsp)
>   56:	00 1a 00 00 00
>   5b:	48 c7 84 24 e8 00 00 	movq   $0x19,0xe8(%rsp)
>   62:	00 19 00 00 00
>   67:	48 c7 84 24 e0 00 00 	movq   $0x18,0xe0(%rsp)
>   6e:	00 18 00 00 00
>   73:	48 c7 84 24 d8 00 00 	movq   $0x17,0xd8(%rsp)
>   7a:	00 17 00 00 00
>   7f:	48 c7 84 24 d0 00 00 	movq   $0x16,0xd0(%rsp)
>   86:	00 16 00 00 00
>   8b:	48 c7 84 24 c8 00 00 	movq   $0x15,0xc8(%rsp)
>   92:	00 15 00 00 00
>   97:	48 c7 84 24 c0 00 00 	movq   $0x14,0xc0(%rsp)
>   9e:	00 14 00 00 00
>   a3:	48 c7 84 24 b8 00 00 	movq   $0x13,0xb8(%rsp)
>   aa:	00 13 00 00 00
>   af:	48 c7 84 24 b0 00 00 	movq   $0x12,0xb0(%rsp)
>   b6:	00 12 00 00 00
>   bb:	48 c7 84 24 a8 00 00 	movq   $0x11,0xa8(%rsp)
>   c2:	00 11 00 00 00
>   c7:	48 c7 84 24 a0 00 00 	movq   $0x10,0xa0(%rsp)
>   ce:	00 10 00 00 00
>   d3:	48 c7 84 24 98 00 00 	movq   $0xf,0x98(%rsp)
>   da:	00 0f 00 00 00
>   df:	48 c7 84 24 90 00 00 	movq   $0xe,0x90(%rsp)
>   e6:	00 0e 00 00 00
>   eb:	48 c7 84 24 88 00 00 	movq   $0xd,0x88(%rsp)
>   f2:	00 0d 00 00 00
>   f7:	48 c7 84 24 80 00 00 	movq   $0xc,0x80(%rsp)
>   fe:	00 0c 00 00 00
>  103:	48 c7 44 24 78 0b 00 	movq   $0xb,0x78(%rsp)
>  10a:	00 00
>  10c:	48 c7 44 24 70 0a 00 	movq   $0xa,0x70(%rsp)
>  113:	00 00
>  115:	48 c7 44 24 68 09 00 	movq   $0x9,0x68(%rsp)
>  11c:	00 00
>  11e:	48 c7 44 24 60 08 00 	movq   $0x8,0x60(%rsp)
>  125:	00 00
>  127:	48 c7 44 24 58 07 00 	movq   $0x7,0x58(%rsp)
>  12e:	00 00
>  130:	48 c7 44 24 50 06 00 	movq   $0x6,0x50(%rsp)
>  137:	00 00
>  139:	48 c7 44 24 48 05 00 	movq   $0x5,0x48(%rsp)
>  140:	00 00
>  142:	48 c7 44 24 40 04 00 	movq   $0x4,0x40(%rsp)
>  149:	00 00
>  14b:	48 c7 44 24 38 03 00 	movq   $0x3,0x38(%rsp)
>  152:	00 00
>  154:	48 c7 44 24 30 02 00 	movq   $0x2,0x30(%rsp)
>  15b:	00 00
>  15d:	48 c7 44 24 28 01 00 	movq   $0x1,0x28(%rsp)
>  164:	00 00
>  166:	48 c7 44 24 20 00 00 	movq   $0x0,0x20(%rsp)
>  16d:	00 00
>  16f:	41 b9 01 00 00 00    	mov    $0x1,%r9d
>  175:	41 b8 00 00 00 00    	mov    $0x0,%r8d
>  17b:	ba 00 00 00 00       	mov    $0x0,%edx
>  180:	b9 00 00 00 00       	mov    $0x0,%ecx
>  185:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>  18c:	00 00 00
>  18f:	ff d0                	callq  *%rax
>     16LLU, 17LLU, 18LLU, 19LLU,
>     20LLU, 21LLU, 22LLU, 23LLU,
>     24LLU, 25LLU, 26LLU, 27LLU,
>     28LLU, 29LLU, 30LLU,  0LLU
>     );
>   return 0;
>  191:	b8 00 00 00 00       	mov    $0x0,%eax
> }
>  196:	c9                   	leaveq
>  197:	c3                   	retq

Disassembly of the -Os case (with 'objdump -S
Build/OvmfX64/DEBUG_GCC48/X64/OvmfPkg/GccBugReproducer/GccBugReproducer-Os/OUTPUT/GccBugReproducer.obj'):

>
> Build/OvmfX64/DEBUG_GCC48/X64/OvmfPkg/GccBugReproducer/GccBugReproducer-Os/OUTPUT/GccBugReproducer.obj:     file format elf64-x86-64
>
>
> Disassembly of section .text.Print4:
>
> 0000000000000000 <Print4>:
>   IN UINT64  Dummy2,
>   IN UINT64  Dummy3,
>   IN BOOLEAN Recursive,
>   IN VA_LIST Marker
>   )
> {
>    0:	41 55                	push   %r13
>    2:	45 88 cd             	mov    %r9b,%r13b
>    5:	41 54                	push   %r12
>    7:	49 89 d4             	mov    %rdx,%r12
>    a:	55                   	push   %rbp
>    b:	48 89 cd             	mov    %rcx,%rbp
>    e:	57                   	push   %rdi
>   )
> {
>   VA_LIST Marker;
>
>   VA_START (Marker, Recursive);
>   Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>    f:	49 8d 78 03          	lea    0x3(%r8),%rdi
>   IN UINT64  Dummy2,
>   IN UINT64  Dummy3,
>   IN BOOLEAN Recursive,
>   IN VA_LIST Marker
>   )
> {
>   13:	56                   	push   %rsi
>   14:	53                   	push   %rbx
>   15:	48 83 ec 48          	sub    $0x48,%rsp
>   19:	48 8b 9c 24 a0 00 00 	mov    0xa0(%rsp),%rbx
>   20:	00
>   UINT64 Value1, Value2, Value3, Value4;
>
>   do {
>     Value1 = VA_ARG (Marker, UINT64);
>   21:	48 8b 13             	mov    (%rbx),%rdx
>     Value2 = VA_ARG (Marker, UINT64);
>   24:	4c 8b 43 08          	mov    0x8(%rbx),%r8
>   28:	48 83 c3 20          	add    $0x20,%rbx
>     Value3 = VA_ARG (Marker, UINT64);
>   2c:	4c 8b 4b f0          	mov    -0x10(%rbx),%r9
>     Value4 = VA_ARG (Marker, UINT64);
>
>     if (!Recursive) {
>   30:	45 84 ed             	test   %r13b,%r13b
>
>   do {
>     Value1 = VA_ARG (Marker, UINT64);
>     Value2 = VA_ARG (Marker, UINT64);
>     Value3 = VA_ARG (Marker, UINT64);
>     Value4 = VA_ARG (Marker, UINT64);
>   33:	48 8b 73 f8          	mov    -0x8(%rbx),%rsi
>
>     if (!Recursive) {
>   37:	75 1d                	jne    56 <Print4+0x56>
>       AsciiPrint ("0x%02Lx 0x%02Lx 0x%02Lx 0x%02Lx\n",
>   39:	48 89 74 24 20       	mov    %rsi,0x20(%rsp)
>   3e:	48 b9 00 00 00 00 00 	movabs $0x0,%rcx
>   45:	00 00 00
>   48:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>   4f:	00 00 00
>   52:	ff d0                	callq  *%rax
>         Value1, Value2, Value3, Value4);
>       return;
>   54:	eb 2f                	jmp    85 <Print4+0x85>
>   ...
>   )
> {
>   VA_LIST Marker;
>
>   VA_START (Marker, Recursive);
>   56:	48 8d 44 24 47       	lea    0x47(%rsp),%rax
>   Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>   5b:	45 31 c9             	xor    %r9d,%r9d
>   5e:	c6 44 24 3f 00       	movb   $0x0,0x3f(%rsp)
>   63:	49 8d 54 24 02       	lea    0x2(%r12),%rdx
>   68:	48 8d 4d 01          	lea    0x1(%rbp),%rcx
>   6c:	49 89 f8             	mov    %rdi,%r8
>   6f:	48 89 44 24 20       	mov    %rax,0x20(%rsp)
>   74:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>   7b:	00 00 00
>   7e:	ff d0                	callq  *%rax
>         Value1, Value2, Value3, Value4);
>       return;
>     }
>     PrintSeveralQuadruplets (Dummy1, Dummy2, Dummy3, FALSE,
>       Value1, Value2, Value3, Value4);
>   } while (Value4 != 0);
>   80:	48 85 f6             	test   %rsi,%rsi
>   83:	75 9c                	jne    21 <Print4+0x21>
> }
>   85:	48 83 c4 48          	add    $0x48,%rsp
>   89:	5b                   	pop    %rbx
>   8a:	5e                   	pop    %rsi
>   8b:	5f                   	pop    %rdi
>   8c:	5d                   	pop    %rbp
>   8d:	41 5c                	pop    %r12
>   8f:	41 5d                	pop    %r13
>   91:	c3                   	retq
>
> Disassembly of section .text.PrintSeveralQuadruplets:
>
> 0000000000000000 <PrintSeveralQuadruplets>:
>   IN UINT64  Dummy2,
>   IN UINT64  Dummy3,
>   IN BOOLEAN Recursive,
>   ...
>   )
> {
>    0:	48 83 ec 38          	sub    $0x38,%rsp
>   VA_LIST Marker;
>
>   VA_START (Marker, Recursive);
>   Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>    4:	48 83 c2 02          	add    $0x2,%rdx
>    8:	48 ff c1             	inc    %rcx
>   ...
>   )
> {
>   VA_LIST Marker;
>
>   VA_START (Marker, Recursive);
>    b:	48 8d 44 24 60       	lea    0x60(%rsp),%rax
>   IN UINT64  Dummy2,
>   IN UINT64  Dummy3,
>   IN BOOLEAN Recursive,
>   ...
>   )
> {
>   10:	44 88 4c 24 58       	mov    %r9b,0x58(%rsp)
>   VA_LIST Marker;
>
>   VA_START (Marker, Recursive);
>   Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>   15:	49 83 c0 03          	add    $0x3,%r8
>   19:	45 0f b6 c9          	movzbl %r9b,%r9d
>   1d:	48 89 44 24 20       	mov    %rax,0x20(%rsp)
>   22:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>   29:	00 00 00
>   2c:	ff d0                	callq  *%rax
>   VA_END (Marker);
> }
>   2e:	48 83 c4 38          	add    $0x38,%rsp
>   32:	c3                   	retq
>
> Disassembly of section .text.ShellAppMain:
>
> 0000000000000000 <ShellAppMain>:
> EFIAPI
> ShellAppMain (
>   IN UINTN Argc,
>   IN CHAR16 **Argv
>   )
> {
>    0:	48 83 ec 48          	sub    $0x48,%rsp
>   )
> {
>   VA_LIST Marker;
>
>   VA_START (Marker, Recursive);
>   Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>    4:	41 b9 01 00 00 00    	mov    $0x1,%r9d
>    a:	41 b8 03 00 00 00    	mov    $0x3,%r8d
>   ...
>   )
> {
>   VA_LIST Marker;
>
>   VA_START (Marker, Recursive);
>   10:	48 8d 44 24 47       	lea    0x47(%rsp),%rax
>   15:	c6 44 24 3f 01       	movb   $0x1,0x3f(%rsp)
>   Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>   1a:	ba 02 00 00 00       	mov    $0x2,%edx
>   1f:	b9 01 00 00 00       	mov    $0x1,%ecx
>   24:	48 89 44 24 20       	mov    %rax,0x20(%rsp)
>   29:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>   30:	00 00 00
>   33:	ff d0                	callq  *%rax
>     20LLU, 21LLU, 22LLU, 23LLU,
>     24LLU, 25LLU, 26LLU, 27LLU,
>     28LLU, 29LLU, 30LLU,  0LLU
>     );
>   return 0;
> }
>   35:	31 c0                	xor    %eax,%eax
>   37:	48 83 c4 48          	add    $0x48,%rsp
>   3b:	c3                   	retq

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
 OvmfPkg/GccBugReproducer/GccBugReproducer-O0.inf | 43 +++++++++++
 OvmfPkg/GccBugReproducer/GccBugReproducer-Os.inf | 43 +++++++++++
 OvmfPkg/GccBugReproducer/GccBugReproducer.c      | 93 ++++++++++++++++++++++++
 OvmfPkg/OvmfPkgX64.dsc                           |  8 ++
 4 files changed, 187 insertions(+)
 create mode 100644 OvmfPkg/GccBugReproducer/GccBugReproducer-O0.inf
 create mode 100644 OvmfPkg/GccBugReproducer/GccBugReproducer-Os.inf
 create mode 100644 OvmfPkg/GccBugReproducer/GccBugReproducer.c

Comments

Sergey Isakov Nov. 14, 2014, 5:45 p.m. UTC | #1
Hi Laszlo,
I didn’t reproduce the bug.
Compilation by gcc-4.9.2-linux-gnu with -flto option
Sizes: with -O0 = 7648, with -Os=7424. It proves optimization was occurred.
Both outputs are good

On 05 нояб. 2014 г., at 16:01, Laszlo Ersek <lersek@redhat.com> wrote:

> Build:
> 
>  . edksetup.sh
>  make -C "$EDK_TOOLS_PATH"
>  nice build -p OvmfPkg/OvmfPkgX64.dsc -b DEBUG -t GCC48 -a X64 \
>    -n $(getconf _NPROCESSORS_ONLN)
> 
> Run:
> 
>  cp Build/OvmfX64/DEBUG_GCC48/FV/OVMF_VARS.fd vars.fd
> 
>  qemu-system-x86_64 \
>    -nodefaults \
>    -nodefconfig \
>    -nographic \
>    \
>    -m 1024 \
>    -enable-kvm \
>    -M pc \
>    \
>    -drive if=pflash,format=raw,file=Build/OvmfX64/DEBUG_GCC48/FV/OVMF_CODE.fd,readonly \
>    -drive if=pflash,format=raw,file=vars.fd \
>    \
>    -chardev stdio,signal=off,mux=on,id=char0 \
>    -mon chardev=char0,mode=readline,default \
>    -serial chardev:char0 \
>    \
>    -chardev file,id=char1,path=ovmf.debug.log \
>    -device isa-debugcon,iobase=0x402,chardev=char1 \
>    \
>    -drive file=fat:Build/OvmfX64/DEBUG_GCC48/X64,id=drive0,if=none,format=raw \
>    -device virtio-blk-pci,drive=drive0
> 
>  Shell> GccBugReproducer-O0
>  0x00 0x01 0x02 0x03
>  0x04 0x05 0x06 0x07
>  0x08 0x09 0x0A 0x0B
>  0x0C 0x0D 0x0E 0x0F
>  0x10 0x11 0x12 0x13
>  0x14 0x15 0x16 0x17
>  0x18 0x19 0x1A 0x1B
>  0x1C 0x1D 0x1E 0x00
> 
>  Shell> GccBugReproducer-Os
>  0x3F443E4000 0x3E95894E00 0x3EB0001800 0x3FF686C000
>  0x3F443E4000 0x3E95894E00 0x3EB0001800 0x3FF686C000
> 
>  Shell> reset -s
> 
> Disassembly of the -O0 case (with 'objdump -S
> Build/OvmfX64/DEBUG_GCC48/X64/OvmfPkg/GccBugReproducer/GccBugReproducer-O0/OUTPUT/GccBugReproducer.obj'):
> 
>> 
>> Build/OvmfX64/DEBUG_GCC48/X64/OvmfPkg/GccBugReproducer/GccBugReproducer-O0/OUTPUT/GccBugReproducer.obj:     file format elf64-x86-64
>> 
>> 
>> Disassembly of section .text.Print4:
>> 
>> 0000000000000000 <Print4>:
>>  IN UINT64  Dummy2,
>>  IN UINT64  Dummy3,
>>  IN BOOLEAN Recursive,
>>  IN VA_LIST Marker
>>  )
>> {
>>   0:	55                   	push   %rbp
>>   1:	48 89 e5             	mov    %rsp,%rbp
>>   4:	48 83 ec 60          	sub    $0x60,%rsp
>>   8:	48 89 4d 10          	mov    %rcx,0x10(%rbp)
>>   c:	48 89 55 18          	mov    %rdx,0x18(%rbp)
>>  10:	4c 89 45 20          	mov    %r8,0x20(%rbp)
>>  14:	44 89 c8             	mov    %r9d,%eax
>>  17:	88 45 28             	mov    %al,0x28(%rbp)
>>  UINT64 Value1, Value2, Value3, Value4;
>> 
>>  do {
>>    Value1 = VA_ARG (Marker, UINT64);
>>  1a:	48 83 45 30 08       	addq   $0x8,0x30(%rbp)
>>  1f:	48 8b 45 30          	mov    0x30(%rbp),%rax
>>  23:	48 8b 40 f8          	mov    -0x8(%rax),%rax
>>  27:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
>>    Value2 = VA_ARG (Marker, UINT64);
>>  2b:	48 83 45 30 08       	addq   $0x8,0x30(%rbp)
>>  30:	48 8b 45 30          	mov    0x30(%rbp),%rax
>>  34:	48 8b 40 f8          	mov    -0x8(%rax),%rax
>>  38:	48 89 45 f0          	mov    %rax,-0x10(%rbp)
>>    Value3 = VA_ARG (Marker, UINT64);
>>  3c:	48 83 45 30 08       	addq   $0x8,0x30(%rbp)
>>  41:	48 8b 45 30          	mov    0x30(%rbp),%rax
>>  45:	48 8b 40 f8          	mov    -0x8(%rax),%rax
>>  49:	48 89 45 e8          	mov    %rax,-0x18(%rbp)
>>    Value4 = VA_ARG (Marker, UINT64);
>>  4d:	48 83 45 30 08       	addq   $0x8,0x30(%rbp)
>>  52:	48 8b 45 30          	mov    0x30(%rbp),%rax
>>  56:	48 8b 40 f8          	mov    -0x8(%rax),%rax
>>  5a:	48 89 45 e0          	mov    %rax,-0x20(%rbp)
>> 
>>    if (!Recursive) {
>>  5e:	80 7d 28 00          	cmpb   $0x0,0x28(%rbp)
>>  62:	75 36                	jne    9a <Print4+0x9a>
>>      AsciiPrint ("0x%02Lx 0x%02Lx 0x%02Lx 0x%02Lx\n",
>>  64:	4c 8b 45 e8          	mov    -0x18(%rbp),%r8
>>  68:	48 8b 4d f0          	mov    -0x10(%rbp),%rcx
>>  6c:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
>>  70:	48 8b 55 e0          	mov    -0x20(%rbp),%rdx
>>  74:	48 89 54 24 20       	mov    %rdx,0x20(%rsp)
>>  79:	4d 89 c1             	mov    %r8,%r9
>>  7c:	49 89 c8             	mov    %rcx,%r8
>>  7f:	48 89 c2             	mov    %rax,%rdx
>>  82:	48 b9 00 00 00 00 00 	movabs $0x0,%rcx
>>  89:	00 00 00
>>  8c:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>>  93:	00 00 00
>>  96:	ff d0                	callq  *%rax
>>        Value1, Value2, Value3, Value4);
>>      return;
>>  98:	eb 53                	jmp    ed <Print4+0xed>
>>    }
>>    PrintSeveralQuadruplets (Dummy1, Dummy2, Dummy3, FALSE,
>>  9a:	48 8b 4d 20          	mov    0x20(%rbp),%rcx
>>  9e:	48 8b 45 18          	mov    0x18(%rbp),%rax
>>  a2:	48 8b 55 e0          	mov    -0x20(%rbp),%rdx
>>  a6:	48 89 54 24 38       	mov    %rdx,0x38(%rsp)
>>  ab:	48 8b 55 e8          	mov    -0x18(%rbp),%rdx
>>  af:	48 89 54 24 30       	mov    %rdx,0x30(%rsp)
>>  b4:	48 8b 55 f0          	mov    -0x10(%rbp),%rdx
>>  b8:	48 89 54 24 28       	mov    %rdx,0x28(%rsp)
>>  bd:	48 8b 55 f8          	mov    -0x8(%rbp),%rdx
>>  c1:	48 89 54 24 20       	mov    %rdx,0x20(%rsp)
>>  c6:	41 b9 00 00 00 00    	mov    $0x0,%r9d
>>  cc:	49 89 c8             	mov    %rcx,%r8
>>  cf:	48 89 c2             	mov    %rax,%rdx
>>  d2:	48 8b 4d 10          	mov    0x10(%rbp),%rcx
>>  d6:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>>  dd:	00 00 00
>>  e0:	ff d0                	callq  *%rax
>>      Value1, Value2, Value3, Value4);
>>  } while (Value4 != 0);
>>  e2:	48 83 7d e0 00       	cmpq   $0x0,-0x20(%rbp)
>>  e7:	0f 85 2d ff ff ff    	jne    1a <Print4+0x1a>
>> }
>>  ed:	c9                   	leaveq
>>  ee:	c3                   	retq
>> 
>> Disassembly of section .text.PrintSeveralQuadruplets:
>> 
>> 0000000000000000 <PrintSeveralQuadruplets>:
>>  IN UINT64  Dummy2,
>>  IN UINT64  Dummy3,
>>  IN BOOLEAN Recursive,
>>  ...
>>  )
>> {
>>   0:	55                   	push   %rbp
>>   1:	48 89 e5             	mov    %rsp,%rbp
>>   4:	48 83 ec 40          	sub    $0x40,%rsp
>>   8:	48 89 4d 10          	mov    %rcx,0x10(%rbp)
>>   c:	48 89 55 18          	mov    %rdx,0x18(%rbp)
>>  10:	4c 89 45 20          	mov    %r8,0x20(%rbp)
>>  14:	44 89 c8             	mov    %r9d,%eax
>>  17:	88 45 28             	mov    %al,0x28(%rbp)
>>  VA_LIST Marker;
>> 
>>  VA_START (Marker, Recursive);
>>  1a:	48 8d 45 28          	lea    0x28(%rbp),%rax
>>  1e:	48 83 c0 08          	add    $0x8,%rax
>>  22:	48 89 45 f8          	mov    %rax,-0x8(%rbp)
>>  Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>>  26:	0f b6 45 28          	movzbl 0x28(%rbp),%eax
>>  2a:	44 0f b6 c0          	movzbl %al,%r8d
>>  2e:	48 8b 45 20          	mov    0x20(%rbp),%rax
>>  32:	4c 8d 50 03          	lea    0x3(%rax),%r10
>>  36:	48 8b 45 18          	mov    0x18(%rbp),%rax
>>  3a:	48 8d 50 02          	lea    0x2(%rax),%rdx
>>  3e:	48 8b 45 10          	mov    0x10(%rbp),%rax
>>  42:	48 8d 48 01          	lea    0x1(%rax),%rcx
>>  46:	48 8b 45 f8          	mov    -0x8(%rbp),%rax
>>  4a:	48 89 44 24 20       	mov    %rax,0x20(%rsp)
>>  4f:	45 89 c1             	mov    %r8d,%r9d
>>  52:	4d 89 d0             	mov    %r10,%r8
>>  55:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>>  5c:	00 00 00
>>  5f:	ff d0                	callq  *%rax
>>  VA_END (Marker);
>>  61:	48 c7 45 f8 00 00 00 	movq   $0x0,-0x8(%rbp)
>>  68:	00
>> }
>>  69:	c9                   	leaveq
>>  6a:	c3                   	retq
>> 
>> Disassembly of section .text.ShellAppMain:
>> 
>> 0000000000000000 <ShellAppMain>:
>> EFIAPI
>> ShellAppMain (
>>  IN UINTN Argc,
>>  IN CHAR16 **Argv
>>  )
>> {
>>   0:	55                   	push   %rbp
>>   1:	48 89 e5             	mov    %rsp,%rbp
>>   4:	48 81 ec 20 01 00 00 	sub    $0x120,%rsp
>>   b:	48 89 4d 10          	mov    %rcx,0x10(%rbp)
>>   f:	48 89 55 18          	mov    %rdx,0x18(%rbp)
>>  PrintSeveralQuadruplets (0, 0, 0, TRUE,
>>  13:	48 c7 84 24 18 01 00 	movq   $0x0,0x118(%rsp)
>>  1a:	00 00 00 00 00
>>  1f:	48 c7 84 24 10 01 00 	movq   $0x1e,0x110(%rsp)
>>  26:	00 1e 00 00 00
>>  2b:	48 c7 84 24 08 01 00 	movq   $0x1d,0x108(%rsp)
>>  32:	00 1d 00 00 00
>>  37:	48 c7 84 24 00 01 00 	movq   $0x1c,0x100(%rsp)
>>  3e:	00 1c 00 00 00
>>  43:	48 c7 84 24 f8 00 00 	movq   $0x1b,0xf8(%rsp)
>>  4a:	00 1b 00 00 00
>>  4f:	48 c7 84 24 f0 00 00 	movq   $0x1a,0xf0(%rsp)
>>  56:	00 1a 00 00 00
>>  5b:	48 c7 84 24 e8 00 00 	movq   $0x19,0xe8(%rsp)
>>  62:	00 19 00 00 00
>>  67:	48 c7 84 24 e0 00 00 	movq   $0x18,0xe0(%rsp)
>>  6e:	00 18 00 00 00
>>  73:	48 c7 84 24 d8 00 00 	movq   $0x17,0xd8(%rsp)
>>  7a:	00 17 00 00 00
>>  7f:	48 c7 84 24 d0 00 00 	movq   $0x16,0xd0(%rsp)
>>  86:	00 16 00 00 00
>>  8b:	48 c7 84 24 c8 00 00 	movq   $0x15,0xc8(%rsp)
>>  92:	00 15 00 00 00
>>  97:	48 c7 84 24 c0 00 00 	movq   $0x14,0xc0(%rsp)
>>  9e:	00 14 00 00 00
>>  a3:	48 c7 84 24 b8 00 00 	movq   $0x13,0xb8(%rsp)
>>  aa:	00 13 00 00 00
>>  af:	48 c7 84 24 b0 00 00 	movq   $0x12,0xb0(%rsp)
>>  b6:	00 12 00 00 00
>>  bb:	48 c7 84 24 a8 00 00 	movq   $0x11,0xa8(%rsp)
>>  c2:	00 11 00 00 00
>>  c7:	48 c7 84 24 a0 00 00 	movq   $0x10,0xa0(%rsp)
>>  ce:	00 10 00 00 00
>>  d3:	48 c7 84 24 98 00 00 	movq   $0xf,0x98(%rsp)
>>  da:	00 0f 00 00 00
>>  df:	48 c7 84 24 90 00 00 	movq   $0xe,0x90(%rsp)
>>  e6:	00 0e 00 00 00
>>  eb:	48 c7 84 24 88 00 00 	movq   $0xd,0x88(%rsp)
>>  f2:	00 0d 00 00 00
>>  f7:	48 c7 84 24 80 00 00 	movq   $0xc,0x80(%rsp)
>>  fe:	00 0c 00 00 00
>> 103:	48 c7 44 24 78 0b 00 	movq   $0xb,0x78(%rsp)
>> 10a:	00 00
>> 10c:	48 c7 44 24 70 0a 00 	movq   $0xa,0x70(%rsp)
>> 113:	00 00
>> 115:	48 c7 44 24 68 09 00 	movq   $0x9,0x68(%rsp)
>> 11c:	00 00
>> 11e:	48 c7 44 24 60 08 00 	movq   $0x8,0x60(%rsp)
>> 125:	00 00
>> 127:	48 c7 44 24 58 07 00 	movq   $0x7,0x58(%rsp)
>> 12e:	00 00
>> 130:	48 c7 44 24 50 06 00 	movq   $0x6,0x50(%rsp)
>> 137:	00 00
>> 139:	48 c7 44 24 48 05 00 	movq   $0x5,0x48(%rsp)
>> 140:	00 00
>> 142:	48 c7 44 24 40 04 00 	movq   $0x4,0x40(%rsp)
>> 149:	00 00
>> 14b:	48 c7 44 24 38 03 00 	movq   $0x3,0x38(%rsp)
>> 152:	00 00
>> 154:	48 c7 44 24 30 02 00 	movq   $0x2,0x30(%rsp)
>> 15b:	00 00
>> 15d:	48 c7 44 24 28 01 00 	movq   $0x1,0x28(%rsp)
>> 164:	00 00
>> 166:	48 c7 44 24 20 00 00 	movq   $0x0,0x20(%rsp)
>> 16d:	00 00
>> 16f:	41 b9 01 00 00 00    	mov    $0x1,%r9d
>> 175:	41 b8 00 00 00 00    	mov    $0x0,%r8d
>> 17b:	ba 00 00 00 00       	mov    $0x0,%edx
>> 180:	b9 00 00 00 00       	mov    $0x0,%ecx
>> 185:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>> 18c:	00 00 00
>> 18f:	ff d0                	callq  *%rax
>>    16LLU, 17LLU, 18LLU, 19LLU,
>>    20LLU, 21LLU, 22LLU, 23LLU,
>>    24LLU, 25LLU, 26LLU, 27LLU,
>>    28LLU, 29LLU, 30LLU,  0LLU
>>    );
>>  return 0;
>> 191:	b8 00 00 00 00       	mov    $0x0,%eax
>> }
>> 196:	c9                   	leaveq
>> 197:	c3                   	retq
> 
> Disassembly of the -Os case (with 'objdump -S
> Build/OvmfX64/DEBUG_GCC48/X64/OvmfPkg/GccBugReproducer/GccBugReproducer-Os/OUTPUT/GccBugReproducer.obj'):
> 
>> 
>> Build/OvmfX64/DEBUG_GCC48/X64/OvmfPkg/GccBugReproducer/GccBugReproducer-Os/OUTPUT/GccBugReproducer.obj:     file format elf64-x86-64
>> 
>> 
>> Disassembly of section .text.Print4:
>> 
>> 0000000000000000 <Print4>:
>>  IN UINT64  Dummy2,
>>  IN UINT64  Dummy3,
>>  IN BOOLEAN Recursive,
>>  IN VA_LIST Marker
>>  )
>> {
>>   0:	41 55                	push   %r13
>>   2:	45 88 cd             	mov    %r9b,%r13b
>>   5:	41 54                	push   %r12
>>   7:	49 89 d4             	mov    %rdx,%r12
>>   a:	55                   	push   %rbp
>>   b:	48 89 cd             	mov    %rcx,%rbp
>>   e:	57                   	push   %rdi
>>  )
>> {
>>  VA_LIST Marker;
>> 
>>  VA_START (Marker, Recursive);
>>  Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>>   f:	49 8d 78 03          	lea    0x3(%r8),%rdi
>>  IN UINT64  Dummy2,
>>  IN UINT64  Dummy3,
>>  IN BOOLEAN Recursive,
>>  IN VA_LIST Marker
>>  )
>> {
>>  13:	56                   	push   %rsi
>>  14:	53                   	push   %rbx
>>  15:	48 83 ec 48          	sub    $0x48,%rsp
>>  19:	48 8b 9c 24 a0 00 00 	mov    0xa0(%rsp),%rbx
>>  20:	00
>>  UINT64 Value1, Value2, Value3, Value4;
>> 
>>  do {
>>    Value1 = VA_ARG (Marker, UINT64);
>>  21:	48 8b 13             	mov    (%rbx),%rdx
>>    Value2 = VA_ARG (Marker, UINT64);
>>  24:	4c 8b 43 08          	mov    0x8(%rbx),%r8
>>  28:	48 83 c3 20          	add    $0x20,%rbx
>>    Value3 = VA_ARG (Marker, UINT64);
>>  2c:	4c 8b 4b f0          	mov    -0x10(%rbx),%r9
>>    Value4 = VA_ARG (Marker, UINT64);
>> 
>>    if (!Recursive) {
>>  30:	45 84 ed             	test   %r13b,%r13b
>> 
>>  do {
>>    Value1 = VA_ARG (Marker, UINT64);
>>    Value2 = VA_ARG (Marker, UINT64);
>>    Value3 = VA_ARG (Marker, UINT64);
>>    Value4 = VA_ARG (Marker, UINT64);
>>  33:	48 8b 73 f8          	mov    -0x8(%rbx),%rsi
>> 
>>    if (!Recursive) {
>>  37:	75 1d                	jne    56 <Print4+0x56>
>>      AsciiPrint ("0x%02Lx 0x%02Lx 0x%02Lx 0x%02Lx\n",
>>  39:	48 89 74 24 20       	mov    %rsi,0x20(%rsp)
>>  3e:	48 b9 00 00 00 00 00 	movabs $0x0,%rcx
>>  45:	00 00 00
>>  48:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>>  4f:	00 00 00
>>  52:	ff d0                	callq  *%rax
>>        Value1, Value2, Value3, Value4);
>>      return;
>>  54:	eb 2f                	jmp    85 <Print4+0x85>
>>  ...
>>  )
>> {
>>  VA_LIST Marker;
>> 
>>  VA_START (Marker, Recursive);
>>  56:	48 8d 44 24 47       	lea    0x47(%rsp),%rax
>>  Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>>  5b:	45 31 c9             	xor    %r9d,%r9d
>>  5e:	c6 44 24 3f 00       	movb   $0x0,0x3f(%rsp)
>>  63:	49 8d 54 24 02       	lea    0x2(%r12),%rdx
>>  68:	48 8d 4d 01          	lea    0x1(%rbp),%rcx
>>  6c:	49 89 f8             	mov    %rdi,%r8
>>  6f:	48 89 44 24 20       	mov    %rax,0x20(%rsp)
>>  74:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>>  7b:	00 00 00
>>  7e:	ff d0                	callq  *%rax
>>        Value1, Value2, Value3, Value4);
>>      return;
>>    }
>>    PrintSeveralQuadruplets (Dummy1, Dummy2, Dummy3, FALSE,
>>      Value1, Value2, Value3, Value4);
>>  } while (Value4 != 0);
>>  80:	48 85 f6             	test   %rsi,%rsi
>>  83:	75 9c                	jne    21 <Print4+0x21>
>> }
>>  85:	48 83 c4 48          	add    $0x48,%rsp
>>  89:	5b                   	pop    %rbx
>>  8a:	5e                   	pop    %rsi
>>  8b:	5f                   	pop    %rdi
>>  8c:	5d                   	pop    %rbp
>>  8d:	41 5c                	pop    %r12
>>  8f:	41 5d                	pop    %r13
>>  91:	c3                   	retq
>> 
>> Disassembly of section .text.PrintSeveralQuadruplets:
>> 
>> 0000000000000000 <PrintSeveralQuadruplets>:
>>  IN UINT64  Dummy2,
>>  IN UINT64  Dummy3,
>>  IN BOOLEAN Recursive,
>>  ...
>>  )
>> {
>>   0:	48 83 ec 38          	sub    $0x38,%rsp
>>  VA_LIST Marker;
>> 
>>  VA_START (Marker, Recursive);
>>  Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>>   4:	48 83 c2 02          	add    $0x2,%rdx
>>   8:	48 ff c1             	inc    %rcx
>>  ...
>>  )
>> {
>>  VA_LIST Marker;
>> 
>>  VA_START (Marker, Recursive);
>>   b:	48 8d 44 24 60       	lea    0x60(%rsp),%rax
>>  IN UINT64  Dummy2,
>>  IN UINT64  Dummy3,
>>  IN BOOLEAN Recursive,
>>  ...
>>  )
>> {
>>  10:	44 88 4c 24 58       	mov    %r9b,0x58(%rsp)
>>  VA_LIST Marker;
>> 
>>  VA_START (Marker, Recursive);
>>  Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>>  15:	49 83 c0 03          	add    $0x3,%r8
>>  19:	45 0f b6 c9          	movzbl %r9b,%r9d
>>  1d:	48 89 44 24 20       	mov    %rax,0x20(%rsp)
>>  22:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>>  29:	00 00 00
>>  2c:	ff d0                	callq  *%rax
>>  VA_END (Marker);
>> }
>>  2e:	48 83 c4 38          	add    $0x38,%rsp
>>  32:	c3                   	retq
>> 
>> Disassembly of section .text.ShellAppMain:
>> 
>> 0000000000000000 <ShellAppMain>:
>> EFIAPI
>> ShellAppMain (
>>  IN UINTN Argc,
>>  IN CHAR16 **Argv
>>  )
>> {
>>   0:	48 83 ec 48          	sub    $0x48,%rsp
>>  )
>> {
>>  VA_LIST Marker;
>> 
>>  VA_START (Marker, Recursive);
>>  Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>>   4:	41 b9 01 00 00 00    	mov    $0x1,%r9d
>>   a:	41 b8 03 00 00 00    	mov    $0x3,%r8d
>>  ...
>>  )
>> {
>>  VA_LIST Marker;
>> 
>>  VA_START (Marker, Recursive);
>>  10:	48 8d 44 24 47       	lea    0x47(%rsp),%rax
>>  15:	c6 44 24 3f 01       	movb   $0x1,0x3f(%rsp)
>>  Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
>>  1a:	ba 02 00 00 00       	mov    $0x2,%edx
>>  1f:	b9 01 00 00 00       	mov    $0x1,%ecx
>>  24:	48 89 44 24 20       	mov    %rax,0x20(%rsp)
>>  29:	48 b8 00 00 00 00 00 	movabs $0x0,%rax
>>  30:	00 00 00
>>  33:	ff d0                	callq  *%rax
>>    20LLU, 21LLU, 22LLU, 23LLU,
>>    24LLU, 25LLU, 26LLU, 27LLU,
>>    28LLU, 29LLU, 30LLU,  0LLU
>>    );
>>  return 0;
>> }
>>  35:	31 c0                	xor    %eax,%eax
>>  37:	48 83 c4 48          	add    $0x48,%rsp
>>  3b:	c3                   	retq
> 
> Contributed-under: TianoCore Contribution Agreement 1.0
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---
> OvmfPkg/GccBugReproducer/GccBugReproducer-O0.inf | 43 +++++++++++
> OvmfPkg/GccBugReproducer/GccBugReproducer-Os.inf | 43 +++++++++++
> OvmfPkg/GccBugReproducer/GccBugReproducer.c      | 93 ++++++++++++++++++++++++
> OvmfPkg/OvmfPkgX64.dsc                           |  8 ++
> 4 files changed, 187 insertions(+)
> create mode 100644 OvmfPkg/GccBugReproducer/GccBugReproducer-O0.inf
> create mode 100644 OvmfPkg/GccBugReproducer/GccBugReproducer-Os.inf
> create mode 100644 OvmfPkg/GccBugReproducer/GccBugReproducer.c
> 
> diff --git a/OvmfPkg/GccBugReproducer/GccBugReproducer-O0.inf b/OvmfPkg/GccBugReproducer/GccBugReproducer-O0.inf
> new file mode 100644
> index 0000000..dd97352
> --- /dev/null
> +++ b/OvmfPkg/GccBugReproducer/GccBugReproducer-O0.inf
> @@ -0,0 +1,43 @@
> +## @file
> +#  An application reproducing local variable corruption in recursive calls with
> +#  gcc-4.8 on the X64 target.
> +#
> +#  Copyright (C) 2014, Red Hat, Inc.
> +#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
> +#
> +#  This program and the accompanying materials are licensed and made available
> +#  under the terms and conditions of the BSD License which accompanies this
> +#  distribution. The full text of the license may be found at
> +#  http://opensource.org/licenses/bsd-license.
> +#
> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
> +#  IMPLIED.
> +#
> +##
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010006
> +  BASE_NAME                      = GccBugReproducer-O0
> +  FILE_GUID                      = 8b779522-e8c8-44c9-a8fb-6472d5323808
> +  MODULE_TYPE                    = UEFI_APPLICATION
> +  VERSION_STRING                 = 0.1
> +  ENTRY_POINT                    = ShellCEntryLib
> +
> +#
> +#  VALID_ARCHITECTURES           = X64
> +#
> +
> +[Sources]
> +  GccBugReproducer.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  ShellPkg/ShellPkg.dec
> +
> +[LibraryClasses]
> +  UefiLib
> +  ShellCEntryLib
> +
> +[BuildOptions]
> +  GCC:DEBUG_GCC48_X64_CC_FLAGS = -O0
> diff --git a/OvmfPkg/GccBugReproducer/GccBugReproducer-Os.inf b/OvmfPkg/GccBugReproducer/GccBugReproducer-Os.inf
> new file mode 100644
> index 0000000..2d23c16
> --- /dev/null
> +++ b/OvmfPkg/GccBugReproducer/GccBugReproducer-Os.inf
> @@ -0,0 +1,43 @@
> +## @file
> +#  An application reproducing local variable corruption in recursive calls with
> +#  gcc-4.8 on the X64 target.
> +#
> +#  Copyright (C) 2014, Red Hat, Inc.
> +#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
> +#
> +#  This program and the accompanying materials are licensed and made available
> +#  under the terms and conditions of the BSD License which accompanies this
> +#  distribution. The full text of the license may be found at
> +#  http://opensource.org/licenses/bsd-license.
> +#
> +#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
> +#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
> +#  IMPLIED.
> +#
> +##
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010006
> +  BASE_NAME                      = GccBugReproducer-Os
> +  FILE_GUID                      = 76bda6c5-c09b-498c-a1c5-699ab23e5c03
> +  MODULE_TYPE                    = UEFI_APPLICATION
> +  VERSION_STRING                 = 0.1
> +  ENTRY_POINT                    = ShellCEntryLib
> +
> +#
> +#  VALID_ARCHITECTURES           = X64
> +#
> +
> +[Sources]
> +  GccBugReproducer.c
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  ShellPkg/ShellPkg.dec
> +
> +[LibraryClasses]
> +  UefiLib
> +  ShellCEntryLib
> +
> +[BuildOptions]
> +  GCC:DEBUG_GCC48_X64_CC_FLAGS = -Os
> diff --git a/OvmfPkg/GccBugReproducer/GccBugReproducer.c b/OvmfPkg/GccBugReproducer/GccBugReproducer.c
> new file mode 100644
> index 0000000..c3ebb20
> --- /dev/null
> +++ b/OvmfPkg/GccBugReproducer/GccBugReproducer.c
> @@ -0,0 +1,93 @@
> +/** @file
> +  An application reproducing local variable corruption in recursive calls with
> +  gcc-4.8 on the X64 target.
> +
> +  Copyright (C) 2014, Red Hat, Inc.
> +  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
> +
> +  This program and the accompanying materials are licensed and made available
> +  under the terms and conditions of the BSD License which accompanies this
> +  distribution. The full text of the license may be found at
> +  http://opensource.org/licenses/bsd-license.
> +
> +  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
> +  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
> +**/
> +#include  <Uefi.h>
> +#include  <Library/UefiLib.h>
> +#include  <Library/ShellCEntryLib.h>
> +
> +VOID
> +EFIAPI
> +PrintSeveralQuadruplets (
> +  IN UINT64  Dummy1,
> +  IN UINT64  Dummy2,
> +  IN UINT64  Dummy3,
> +  IN BOOLEAN Recursive,
> +  ...
> +  );
> +
> +VOID
> +EFIAPI
> +Print4 (
> +  IN UINT64  Dummy1,
> +  IN UINT64  Dummy2,
> +  IN UINT64  Dummy3,
> +  IN BOOLEAN Recursive,
> +  IN VA_LIST Marker
> +  )
> +{
> +  UINT64 Value1, Value2, Value3, Value4;
> +
> +  do {
> +    Value1 = VA_ARG (Marker, UINT64);
> +    Value2 = VA_ARG (Marker, UINT64);
> +    Value3 = VA_ARG (Marker, UINT64);
> +    Value4 = VA_ARG (Marker, UINT64);
> +
> +    if (!Recursive) {
> +      AsciiPrint ("0x%02Lx 0x%02Lx 0x%02Lx 0x%02Lx\n",
> +        Value1, Value2, Value3, Value4);
> +      return;
> +    }
> +    PrintSeveralQuadruplets (Dummy1, Dummy2, Dummy3, FALSE,
> +      Value1, Value2, Value3, Value4);
> +  } while (Value4 != 0);
> +}
> +
> +VOID
> +EFIAPI
> +PrintSeveralQuadruplets (
> +  IN UINT64  Dummy1,
> +  IN UINT64  Dummy2,
> +  IN UINT64  Dummy3,
> +  IN BOOLEAN Recursive,
> +  ...
> +  )
> +{
> +  VA_LIST Marker;
> +
> +  VA_START (Marker, Recursive);
> +  Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
> +  VA_END (Marker);
> +}
> +
> +INTN
> +EFIAPI
> +ShellAppMain (
> +  IN UINTN Argc,
> +  IN CHAR16 **Argv
> +  )
> +{
> +  PrintSeveralQuadruplets (0, 0, 0, TRUE,
> +     0LLU,  1LLU,  2LLU,  3LLU,
> +     4LLU,  5LLU,  6LLU,  7LLU,
> +     8LLU,  9LLU, 10LLU, 11LLU,
> +    12LLU, 13LLU, 14LLU, 15LLU,
> +    16LLU, 17LLU, 18LLU, 19LLU,
> +    20LLU, 21LLU, 22LLU, 23LLU,
> +    24LLU, 25LLU, 26LLU, 27LLU,
> +    28LLU, 29LLU, 30LLU,  0LLU
> +    );
> +  return 0;
> +}
> diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
> index df59272..b518746 100644
> --- a/OvmfPkg/OvmfPkgX64.dsc
> +++ b/OvmfPkg/OvmfPkgX64.dsc
> @@ -600,3 +600,11 @@
> !endif
> 
>   OvmfPkg/PlatformDxe/Platform.inf
> +  OvmfPkg/GccBugReproducer/GccBugReproducer-O0.inf {
> +    <LibraryClasses>
> +      ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
> +  }
> +  OvmfPkg/GccBugReproducer/GccBugReproducer-Os.inf {
> +    <LibraryClasses>
> +      ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
> +  }
> -- 
> 1.8.3.1
> 
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> edk2-devel mailing list
> edk2-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/edk2-devel
------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
Laszlo Ersek Nov. 14, 2014, 6:02 p.m. UTC | #2
On 11/14/14 18:45, Sergey Isakov wrote:
> Hi Laszlo,
> I didn’t reproduce the bug.
> Compilation by gcc-4.9.2-linux-gnu with -flto option
> Sizes: with -O0 = 7648, with -Os=7424. It proves optimization was occurred.
> Both outputs are good

Thanks! That's good news. Seems to imply that the issue is specific to
my "gcc (GCC) 4.8.2 20140120 (Red Hat 4.8.2-16)".

I contacted a few colleagues already, we'll see if I get any answers.

Thanks!
Laszlo

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk
diff mbox

Patch

diff --git a/OvmfPkg/GccBugReproducer/GccBugReproducer-O0.inf b/OvmfPkg/GccBugReproducer/GccBugReproducer-O0.inf
new file mode 100644
index 0000000..dd97352
--- /dev/null
+++ b/OvmfPkg/GccBugReproducer/GccBugReproducer-O0.inf
@@ -0,0 +1,43 @@ 
+## @file
+#  An application reproducing local variable corruption in recursive calls with
+#  gcc-4.8 on the X64 target.
+#
+#  Copyright (C) 2014, Red Hat, Inc.
+#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+#
+#  This program and the accompanying materials are licensed and made available
+#  under the terms and conditions of the BSD License which accompanies this
+#  distribution. The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
+#  IMPLIED.
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010006
+  BASE_NAME                      = GccBugReproducer-O0
+  FILE_GUID                      = 8b779522-e8c8-44c9-a8fb-6472d5323808
+  MODULE_TYPE                    = UEFI_APPLICATION
+  VERSION_STRING                 = 0.1
+  ENTRY_POINT                    = ShellCEntryLib
+
+#
+#  VALID_ARCHITECTURES           = X64
+#
+
+[Sources]
+  GccBugReproducer.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+  UefiLib
+  ShellCEntryLib
+
+[BuildOptions]
+  GCC:DEBUG_GCC48_X64_CC_FLAGS = -O0
diff --git a/OvmfPkg/GccBugReproducer/GccBugReproducer-Os.inf b/OvmfPkg/GccBugReproducer/GccBugReproducer-Os.inf
new file mode 100644
index 0000000..2d23c16
--- /dev/null
+++ b/OvmfPkg/GccBugReproducer/GccBugReproducer-Os.inf
@@ -0,0 +1,43 @@ 
+## @file
+#  An application reproducing local variable corruption in recursive calls with
+#  gcc-4.8 on the X64 target.
+#
+#  Copyright (C) 2014, Red Hat, Inc.
+#  Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
+#
+#  This program and the accompanying materials are licensed and made available
+#  under the terms and conditions of the BSD License which accompanies this
+#  distribution. The full text of the license may be found at
+#  http://opensource.org/licenses/bsd-license.
+#
+#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR
+#  IMPLIED.
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010006
+  BASE_NAME                      = GccBugReproducer-Os
+  FILE_GUID                      = 76bda6c5-c09b-498c-a1c5-699ab23e5c03
+  MODULE_TYPE                    = UEFI_APPLICATION
+  VERSION_STRING                 = 0.1
+  ENTRY_POINT                    = ShellCEntryLib
+
+#
+#  VALID_ARCHITECTURES           = X64
+#
+
+[Sources]
+  GccBugReproducer.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  ShellPkg/ShellPkg.dec
+
+[LibraryClasses]
+  UefiLib
+  ShellCEntryLib
+
+[BuildOptions]
+  GCC:DEBUG_GCC48_X64_CC_FLAGS = -Os
diff --git a/OvmfPkg/GccBugReproducer/GccBugReproducer.c b/OvmfPkg/GccBugReproducer/GccBugReproducer.c
new file mode 100644
index 0000000..c3ebb20
--- /dev/null
+++ b/OvmfPkg/GccBugReproducer/GccBugReproducer.c
@@ -0,0 +1,93 @@ 
+/** @file
+  An application reproducing local variable corruption in recursive calls with
+  gcc-4.8 on the X64 target.
+
+  Copyright (C) 2014, Red Hat, Inc.
+  Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
+
+  This program and the accompanying materials are licensed and made available
+  under the terms and conditions of the BSD License which accompanies this
+  distribution. The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT
+  WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include  <Uefi.h>
+#include  <Library/UefiLib.h>
+#include  <Library/ShellCEntryLib.h>
+
+VOID
+EFIAPI
+PrintSeveralQuadruplets (
+  IN UINT64  Dummy1,
+  IN UINT64  Dummy2,
+  IN UINT64  Dummy3,
+  IN BOOLEAN Recursive,
+  ...
+  );
+
+VOID
+EFIAPI
+Print4 (
+  IN UINT64  Dummy1,
+  IN UINT64  Dummy2,
+  IN UINT64  Dummy3,
+  IN BOOLEAN Recursive,
+  IN VA_LIST Marker
+  )
+{
+  UINT64 Value1, Value2, Value3, Value4;
+
+  do {
+    Value1 = VA_ARG (Marker, UINT64);
+    Value2 = VA_ARG (Marker, UINT64);
+    Value3 = VA_ARG (Marker, UINT64);
+    Value4 = VA_ARG (Marker, UINT64);
+
+    if (!Recursive) {
+      AsciiPrint ("0x%02Lx 0x%02Lx 0x%02Lx 0x%02Lx\n",
+        Value1, Value2, Value3, Value4);
+      return;
+    }
+    PrintSeveralQuadruplets (Dummy1, Dummy2, Dummy3, FALSE,
+      Value1, Value2, Value3, Value4);
+  } while (Value4 != 0);
+}
+
+VOID
+EFIAPI
+PrintSeveralQuadruplets (
+  IN UINT64  Dummy1,
+  IN UINT64  Dummy2,
+  IN UINT64  Dummy3,
+  IN BOOLEAN Recursive,
+  ...
+  )
+{
+  VA_LIST Marker;
+
+  VA_START (Marker, Recursive);
+  Print4 (Dummy1 + 1, Dummy2 + 2, Dummy3 + 3, Recursive, Marker);
+  VA_END (Marker);
+}
+
+INTN
+EFIAPI
+ShellAppMain (
+  IN UINTN Argc,
+  IN CHAR16 **Argv
+  )
+{
+  PrintSeveralQuadruplets (0, 0, 0, TRUE,
+     0LLU,  1LLU,  2LLU,  3LLU,
+     4LLU,  5LLU,  6LLU,  7LLU,
+     8LLU,  9LLU, 10LLU, 11LLU,
+    12LLU, 13LLU, 14LLU, 15LLU,
+    16LLU, 17LLU, 18LLU, 19LLU,
+    20LLU, 21LLU, 22LLU, 23LLU,
+    24LLU, 25LLU, 26LLU, 27LLU,
+    28LLU, 29LLU, 30LLU,  0LLU
+    );
+  return 0;
+}
diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc
index df59272..b518746 100644
--- a/OvmfPkg/OvmfPkgX64.dsc
+++ b/OvmfPkg/OvmfPkgX64.dsc
@@ -600,3 +600,11 @@ 
 !endif
 
   OvmfPkg/PlatformDxe/Platform.inf
+  OvmfPkg/GccBugReproducer/GccBugReproducer-O0.inf {
+    <LibraryClasses>
+      ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
+  }
+  OvmfPkg/GccBugReproducer/GccBugReproducer-Os.inf {
+    <LibraryClasses>
+      ShellCEntryLib|ShellPkg/Library/UefiShellCEntryLib/UefiShellCEntryLib.inf
+  }