小编Gil*_*ich的帖子

musl-gcc:对__memcpy_chk的未定义引用

我需要针对musl-libc编译一个C程序,以使其在嵌入式设备上运行。但是,我无法编译该程序。源代码取决于我传递给链接器的几个库,如下所示:

/usr/local/musl/bin/musl-gcc app.c -o app -I../lib -lzlog -lfilter

这是我得到的输出:

/usr/local/musl/lib/libzlog.a(category.o): In function `strcpy':
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__memcpy_chk'
/usr/local/musl/lib/libzlog.a(conf.o): In function `strcpy':
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__strcpy_chk'
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__strcpy_chk'
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__strcpy_chk'
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__strcpy_chk'
/usr/local/musl/lib/libzlog.a(event.o): In function `sprintf':
/usr/include/x86_64-linux-gnu/bits/stdio2.h:33: undefined reference to `__sprintf_chk'
/usr/include/x86_64-linux-gnu/bits/stdio2.h:33: undefined reference to `__sprintf_chk'
/usr/local/musl/lib/libzlog.a(format.o): In function `memcpy':
/usr/include/x86_64-linux-gnu/bits/string3.h:53: undefined reference to `__memcpy_chk'
/usr/local/musl/lib/libzlog.a(record.o): In function `strcpy':
/usr/include/x86_64-linux-gnu/bits/string3.h:110: undefined reference to `__memcpy_chk'
/usr/local/musl/lib/libzlog.a(rotater.o): In function `snprintf':
/usr/include/x86_64-linux-gnu/bits/stdio2.h:64: undefined …
Run Code Online (Sandbox Code Playgroud)

c gcc musl

5
推荐指数
1
解决办法
724
查看次数

比较单元测试中的当前时间

我目前正在编写一个与字符串进行比较的单元测试。第一个字符串是使用函数生成的。另一个是硬编码的并用作参考。我的问题是,创建第一个字符串的函数将精确到秒的当前时间 (time.Now()) 注入到字符串中。目前我也做了同样的事情作为参考,但这对我来说似乎很丑陋。我的机器运行得足够快,因此测试可以通过,但我不想依赖它。

进行此类测试的一般技术是什么?

unit-testing go

3
推荐指数
1
解决办法
4900
查看次数

Go 的 once 类型的效率测量

我有一段代码,我只想运行一次以进行初始化。到目前为止,我使用 sync.Mutex 结合 if 子句来测试它是否已经运行。后来我在同一个同步包中遇到了一次类型和它的 DO() 函数。

实现如下https://golang.org/src/sync/once.go

func (o *Once) Do(f func()) {
    if atomic.LoadUint32(&o.done) == 1 {
        return
    }
    // Slow-path.
    o.m.Lock()
    defer o.m.Unlock()
    if o.done == 0 {
        defer atomic.StoreUint32(&o.done, 1)
        f()
    }
}
Run Code Online (Sandbox Code Playgroud)

看代码,和我之前用的基本一样。与 if 子句结合的互斥锁。但是,添加的函数调用使这对我来说似乎效率很低。我做了一些测试并尝试了各种版本:

func test1() {
    o.Do(func() {
        // Do smth
    })
    wg.Done()
}

func test2() {
    m.Lock()
    if !b {
        func() {
            // Do smth
        }()
    }
    b = true
    m.Unlock()
    wg.Done()
}

func test3() {
    if !b {
        m.Lock() …
Run Code Online (Sandbox Code Playgroud)

performance synchronization mutex go

-1
推荐指数
1
解决办法
585
查看次数

标签 统计

go ×2

c ×1

gcc ×1

musl ×1

mutex ×1

performance ×1

synchronization ×1

unit-testing ×1