Navigation Menu

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

ISPC doesn't comply with Win64 ABI #1318

Closed
Myriachan opened this issue Apr 25, 2018 · 1 comment · Fixed by #2630
Closed

ISPC doesn't comply with Win64 ABI #1318

Myriachan opened this issue Apr 25, 2018 · 1 comment · Fixed by #2630
Assignees

Comments

@Myriachan
Copy link

ISPC does not fully comply with the Windows x86-64 ABI. In all Windows ABIs except x86-32, every function that modifies the stack pointer is required to have an entry in the exception tables (.pdata and .xdata sections). This allows the stack to be unwound properly in the event of an exception. Only x86-32 Windows is exempt from this rule: x86-64, ARMv7-Thumb2 and ARM64 Windows all use exception tables.

Without these exception tables, if an exception occurs, __try blocks will not be respected, and the process will simply crash. In addition, call stacks will not be generated properly in a crash dump or when debugging into ISPC-generated code.

There are additional strict rules about the format of prolog and epilog code, but I didn't see any issues there.

https://msdn.microsoft.com/en-us/library/ms235286.aspx

@nurmukhametov nurmukhametov self-assigned this Aug 21, 2023
@nurmukhametov
Copy link
Collaborator

PR #2630 adds uwtable to ISPC functions. It leads to generation of unwind info, so .pdata is not empty.

Consider the following example:

export noinline uniform int BugFunction(uniform float x, uniform float y)
{
	uniform int a[100];
	uniform int sum = 0;
	for (uniform int i = 0; i < 100; i++)
		sum += a[i];
	return sum;
}
extern "C" uniform int ispc() {
  uniform int result = BugFunction(1.0f, 2.0f);
  return result;
}

It is compiled by the following command:

> ispc.exe --target=host -O0 -o .\uwtable\ex.ispc.obj --emit-obj .\ex.ispc

Without uwtable attributes, there is no .pdata section and unwind info is empty:

> llvm-objdump.exe --section-headers .\ex.ispc.obj

.\ex.ispc.obj:  file format coff-x86-64

Sections:
Idx Name          Size     VMA              Type
  0 .text         000001d6 0000000000000000 TEXT
  1 .data         00000000 0000000000000000 DATA
  2 .bss          00000000 0000000000000000 BSS
  3 .rdata        00000004 0000000000000000 DATA
  4 .rdata        00000004 0000000000000000 DATA
  5 .drectve      00000033 0000000000000000

> llvm-objdump.exe --unwind-info .\ex.ispc.obj

.\ex.ispc.obj:  file format coff-x86-64
Unwind info:

With uwtable attribute, there is .pdata section and corresponding unwind info for 2 functions:

> llvm-objdump.exe --section-headers .\ex.ispc.obj

.\ex.ispc.obj:  file format coff-x86-64

Sections:
Idx Name          Size     VMA              Type
  0 .text         000001d6 0000000000000000 TEXT
  1 .data         00000000 0000000000000000 DATA
  2 .bss          00000000 0000000000000000 BSS
  3 .xdata        00000014 0000000000000000 DATA
  4 .rdata        00000004 0000000000000000 DATA
  5 .rdata        00000004 0000000000000000 DATA
  6 .drectve      00000033 0000000000000000
  7 .pdata        00000018 0000000000000000 DATA

> llvm-objdump.exe --unwind-info .\ex.ispc.obj

.\ex.ispc.obj:  file format coff-x86-64
Unwind info:

Function Table:
  Start Address: .text
  End Address: .text + 0x00c6
  Unwind Info Address: .xdata
    Version: 1
    Flags: 0
    Size of prolog: 16
    Number of Codes: 4
    Frame register: RBP
    Frame offset: 128
    Unwind Codes:
      0x10: UOP_SetFPReg
      0x08: UOP_AllocLarge 62
      0x01: UOP_PushNonVol RBP

Function Table:
  Start Address: .text + 0x00d0
  End Address: .text + 0x013f
  Unwind Info Address: .xdata + 0x000c
    Version: 1
    Flags: 0
    Size of prolog: 4
    Number of Codes: 1
    No frame pointer used
    Unwind Codes:
      0x04: UOP_AllocSmall 72

Regarding .xdata section, no additional information.

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

Successfully merging a pull request may close this issue.

2 participants