Skip to content

placement new does not return properly aligned instance #73409

Closed

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

Activity

  1. ghost added
    untriaged
    on Aug 4, 2022
  2. added
    area-CodeGen-coreclr
    on Aug 4, 2022
  3. self-assigned this
    on Aug 5, 2022
  4. removed
    untriaged
    on Aug 5, 2022
  5. added this to the 7.0.0 milestone on Aug 5, 2022
  6. added a commit that references this issue on Aug 5, 2022
    e5ccd58
  7. ghost added
    in-pr
    on Aug 5, 2022
  8. added a commit that references this issue on Aug 5, 2022
    3fd454a
  9. ghost removed
    in-pr
    on Aug 5, 2022
  10. ghost locked as resolved and limited conversation to collaborators on Sep 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions