Skip to content

core on memory align for SIMD #3091

Description

@icexin

Describe the bug
如代码所示

__m128i v = _mm_load_si128(reinterpret_cast<__m128i*>(&value));

_mm_load_si128指令需要内存16字节对齐,而 value 来自与栈上的一个变量,不一定满足情况。

AtomicInteger128::load 函数也会有这个问题

__m128i value = _mm_load_si128(reinterpret_cast<const __m128i*>(&_value));

To Reproduce
一个简单的dummy server,启动就会core.

#include <brpc/server.h>
#include <gflags/gflags.h>
#include <thread>

int main(int argc, char* argv[]) {
    google::ParseCommandLineFlags(&argc, &argv, true);
    int ret = brpc::StartDummyServerAt(7447);
    if (ret != 0) {
        LOG(ERROR) << "Failed to start dummy server";
        return 1;
    }
    std::this_thread::sleep_for(std::chrono::seconds(1000));
    return 0;
}

Expected behavior

Versions
OS: ubuntu20.04
Compiler: clang 12
brpc: 1.14.1
protobuf: 27.1

Additional context/screenshots

core dump stack

Thread 7 "dummy_server" received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff39fe700 (LWP 96948)]
0x0000000000758aa0 in bthread::AtomicInteger128::store (this=0x7ffff03ff040, value=...) at external/brpc+/src/bthread/task_group.cpp:110
110         __m128i v = _mm_load_si128(reinterpret_cast<__m128i*>(&value));
(gdb) bt
#0  0x0000000000758aa0 in bthread::AtomicInteger128::store (this=0x7ffff03ff040, value=...) at external/brpc+/src/bthread/task_group.cpp:110
#1  0x000000000075e3fe in bthread::TaskGroup::AtomicCPUTimeStat::store (this=0x7ffff03ff040, cpu_time_stat=...) at external/brpc+/src/bthread/task_group.h:293
#2  0x000000000075a163 in bthread::TaskGroup::init (this=0x7ffff03ff000, runqueue_capacity=4096) at external/brpc+/src/bthread/task_group.cpp:326
#3  0x000000000076a443 in bthread::TaskControl::create_group (this=0x7ffff745f400, tag=0) at external/brpc+/src/bthread/task_control.cpp:133
#4  0x0000000000769883 in bthread::TaskControl::worker_thread (arg=0x7ffff75fce40) at external/brpc+/src/bthread/task_control.cpp:93
#5  0x00007ffff7f93609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#6  0x00007ffff7ad4353 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions