tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] BUG: code generation problem in i386-gen.c:gcall_or_jmp()


From: 张博洋
Subject: [Tinycc-devel] BUG: code generation problem in i386-gen.c:gcall_or_jmp()
Date: Sat, 9 Sep 2017 11:02:37 +0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

Hello,

I found 3 problems in i386-gen.c:gcall_or_jmp().

(1) There is a fix for extending return value to whole register, however, this fix is in the constant case only, if a call is indirect, this fix will not be applied and the result will be wrong.

(2) The fix is for 'call' and if 'is_jmp' == 1, it will generate redundant code.

(3) Calling constant should use the indirect way. For example, if someone write "((void (*)(void)) 0x12345678)()" in a DLL, the generated code will be "CALL 0x12345678". However, because the imm in CALL instruction is PC related, when the DLL is relocated, the call target will be wrong.



I provided a patch and two testcase.



'test-movzx-movsx.c' is for problem (1) and (2).
run it with:
  tcc -run test-movzx-movsx.c

expected output is:
  0000ABCE 0000ABCE
  FFFFABCE FFFFABCE
  000000CE 000000CE
  FFFFFFCE FFFFFFCE

  0000ABCE 0000ABCE
  FFFFABCE FFFFABCE
  000000CE 000000CE
  FFFFFFCE FFFFFFCE




the other two files are for problem (3).
run it with:

# set DLL base at 0x400000 to force a relocation
tcc -shared -Wl,-Ttext=0x00400000 test-call-constant-dll.c

tcc -L. -ltest-call-constant-dll -run test-call-constant-run.c

expected output is:
  by pointer variable: FEEDBEEF
  by pointer constant: FEEDBEEF




Thanks
Zhang Boyang

Attachment: fixcall.patch
Description: Text Data

Attachment: test-call-constant-dll.c
Description: Text Data

Attachment: test-call-constant-run.c
Description: Text Data

Attachment: test-movzx-movsx.c
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]