Skip to content

placement new does not return properly aligned instance #73409

@RobertHenry6bev

Description

@RobertHenry6bev

Description

static char CILJitBuff[sizeof(CILJit)];

Code in and around CILJitSingleton is returning a pointer in to a static char[] CILJitBuff, which in turn is returned from a placement new invocation. operator new is supposed to return memory aligned to __STDCPP_DEFAULT_NEW_ALIGNMENT__ which for linux x64 is 16.

When I link this code in CILJitBuff is not aligned. However, my build system takes liberties, so perhaps there is an out-of-band linker specification somewhere that tells the linker to align to 0 mod 16.

For gcc/clang, putting

__attribute__ ((__aligned__(__STDCPP_DEFAULT_NEW_ALIGNMENT__)))

on the declaration of CILJitBuf makes the alignment problem go away, but this is unlikely to port to MSVC,

Reproduction Steps

Compile with clang-14 -fsanitize=undefined and wait for the runtime checker to complain at the call to placement new.

Expected behavior

should return properly aligned data, and no observed runtime error

Actual behavior

run time error via -fsanitize=undefined and not suppressing all unaligned faults.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

/cc @AaronRob

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions