Skip to content

[Issue]: Undefined behavior (misaligned allocation) for Semaphores in Thread #118

Closed
@LunNova

Description

@LunNova

Problem Description

/build/source/rocclr/thread/thread.cpp:39:18: runtime error: constructor call on misaligned address 0x506000010be0 for type 'Semaphore', which requires 64 byte alignment
0x506000010be0: note: pointer points here
 00 00 00 00  be be be be be be be be  be be be be be be be be  be be be be be be be be  be be be be
              ^ 
    #0 0x7fff868239f7 in create /build/source/rocclr/thread/thread.cpp:39
    #1 0x7fff86823416 in Thread /build/source/rocclr/thread/thread.cpp:52
    #2 0x7fff8682303c in HostThread /build/source/rocclr/thread/thread.cpp:32
    #3 0x7fff86824905 in amd::Thread::init() (/nix/store/2yvyn8dgbwxm0fihv1zqc6z86fwr1dk5-rocm-hip-libraries-meta/lib/libamdhip64.so.6+0xc24905)

The three Semaphore instances created with operator new in Thread are created with a misaligned address, causing a undefined behavior error on library init if built with -fsanitize=undefined

created_ = new Semaphore();
lock_ = new Semaphore();
suspend_ = new Semaphore();

I'm not sure why. Semaphore is marked alignas(64) and if I understand right operator new should handle this as of C++17.

Operating System

NixOS

CPU

7773

GPU

MI210

ROCm Version

ROCm 6.3.0

ROCm Component

clr

Steps to Reproduce

Build CLR with -fsanitize=undefined, dlopen libamdhip64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions