标签: glibc

GCC中strlen()的实现在哪里?

有人能指出我strlen()在海湾合作委员会的定义吗?我现在大约半小时一直在试用版本4.4.2(当谷歌疯狂时),我似乎无法找到strlen()实际实现的位置.

c glibc strlen

19
推荐指数
5
解决办法
5万
查看次数

如何在x86_64机器上编译glibc 32bit

我正在尝试在x86_64上编译glibc(作为辅助,而不是系统替换)2.6,并试图让它生成32位对象.当我给它一个标准配置时,它编译得很好,产生通常的64位库对象.一些信息:

$ uname -a
Linux localhost.localdomain 2.6.18-164.11.1.el5 #1 SMP Wed Jan 20 07:32:21 \
EST 2010 x86_64 x86_64 x86_64 GNU/Linux

$ cat /etc/redhat-release
CentOS release 5.4 (Final)
Run Code Online (Sandbox Code Playgroud)

除其他外,我尝试了以下内容:

尝试1:

$ # [in build/glibc-2.6]
$ ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \
                                --with-cpu=i386-pc-linux-gnu

...

checking sysdep dirs... configure: error: The i386-pc-linux-gnu
subspecies of x86_64 is not supported."
Run Code Online (Sandbox Code Playgroud)

尝试2:

$ ../../src/glibc-2.6/configure --prefix=$HOME/glibc32-2.6 \
                                --host=i386-pc-linux-gnu

...

$ make
Run Code Online (Sandbox Code Playgroud)

配置成功,但make会导致编译错误流,如下所示:

nptl/sysdeps/i386/tls.h:65:3: error: #error "TLS support is required."
In file included from include/tls.h:6,
                 from sysdeps/unix/sysv/linux/i386/sysdep.h:30,
                 from <stdin>:1: …
Run Code Online (Sandbox Code Playgroud)

linux glibc

19
推荐指数
3
解决办法
3万
查看次数

glibc strlen()实现如何工作

strlen()从K&R只需要几行.

int strlen(char *s)
{
    char *p = s;
    while (*p != '\0')
        p++;
    return p - s;
}
Run Code Online (Sandbox Code Playgroud)

但是glibc版本要长得多.为简单起见,我删除了所有注释和64位实现,提取的版本strlen()如下所示:

size_t strlen(const char *str)
{
    const char *char_ptr;
    const unsigned long int *longword_ptr;
    unsigned long int longword, magic_bits, himagic, lomagic;

    for (char_ptr = str; ((unsigned long int) char_ptr 
             & (sizeof (longword) - 1)) != 0; ++char_ptr)
       if (*char_ptr == '\0')
           return char_ptr - str;

    longword_ptr = (unsigned long int *) char_ptr;

    himagic = 0x80808080L; …
Run Code Online (Sandbox Code Playgroud)

c string performance glibc

18
推荐指数
1
解决办法
3739
查看次数

为什么glibc的sscanf比Linux上的fscanf慢得多?

我在x86_64 Linux上使用GCC 4.8和glibc 2.19.

在为不同的问题使用不同的输入法时,我比较fscanfsscanf.具体来说,我要fscanf直接使用标准输入:

char s[128]; int n;

while (fscanf(stdin, "%127s %d", s, &n) == 2) { }
Run Code Online (Sandbox Code Playgroud)

或者我首先将整个输入读入缓冲区然后遍历缓冲区sscanf.(将所有内容读入缓冲区需要花费很少的时间.)

char s[128]; int n;
char const * p = my_data;

for (int b; sscanf(p, "%127s %d%n", s, &n, &b) == 2; p += b) { }
Run Code Online (Sandbox Code Playgroud)

令我惊讶的是,该fscanf版本是大大加快.例如,处理数以万计的行fscanf需要这么长时间:

10000       0.003927487 seconds time elapsed
20000       0.006860206 seconds time elapsed
30000       0.007933329 seconds time elapsed
40000       0.012881912 …
Run Code Online (Sandbox Code Playgroud)

c performance glibc scanf

18
推荐指数
2
解决办法
1984
查看次数

为什么log2和log1p比log和log10快得多?

在玩这个问题时,我注意到一些我无法解释的关于相对表现的事情np.log2,np.log并且np.log10:

In [1]: %%timeit x = np.random.rand(100000)
   ....: np.log2(x)
   ....: 
1000 loops, best of 3: 1.31 ms per loop

In [2]: %%timeit x = np.random.rand(100000)
np.log(x)
   ....: 
100 loops, best of 3: 3.64 ms per loop

In [3]: %%timeit x = np.random.rand(100000)
np.log10(x)
   ....: 
100 loops, best of 3: 3.93 ms per loop
Run Code Online (Sandbox Code Playgroud)

np.log2np.log和和快约3倍np.log10.或许甚至更直观地np.log1p(x)计算ln(x + 1),与以下内容相同np.log2:

In [4]: %%timeit x = …
Run Code Online (Sandbox Code Playgroud)

python performance numpy logarithm glibc

18
推荐指数
3
解决办法
3813
查看次数

在 Linux 上安装节点:/lib64/libm.so.6:版本“GLIBC_2.27”未找到(节点需要)错误

我已经关注了这个 - How to install node.tar.xz file in linux

最后在执行 node --version 时我收到这些错误 -

在此输入图像描述

接下来应该做什么?无法找到适合我的场景的正确步骤。

linux terminal glibc node.js

18
推荐指数
1
解决办法
6万
查看次数

libc源位置 - 用于下载或在线查看?

对不起,我知道这是愚蠢的但linux libc源代码在哪里?我从GNU下载的内容似乎不是我想要的,特别是我在pthreads函数系列中找不到任何内容.

某处是否存在在线(高压交叉引用)版本?

c linux posix glibc pthreads

17
推荐指数
3
解决办法
2万
查看次数

我可以欺骗libc(GLIBC_2.13)加载它没有的符号(来自GLIBC_2.15)吗?

在我尝试将"Steam for Linux"用于Debian时,我遇到了一个问题.libcef(Chromium Embedded Framework)可以正常使用GLIBC_2.13(Debian测试中的eglibc可以提供),但需要一个讨厌的额外函数GLIBC_2.15(eglibc无法提供):

$ readelf -s libcef.so | grep -E "@GLIBC_2\.1[4567]"
1037: 00000000     0 FUNC    GLOBAL DEFAULT  UND __fdelt_chk@GLIBC_2.15 (49)
2733: 00000000     0 FUNC    GLOBAL DEFAULT  UND __fdelt_chk@@GLIBC_2.15
Run Code Online (Sandbox Code Playgroud)

我的攻击计划是LD_PRELOAD一个提供这些功能的垫片库.这似乎不起作用.我真的想避免安装GLIBC_2.17(因为它是在Debian实验中;甚至Debian sid仍然有GLIBC_2.13).


这就是我尝试过的.

fdelt_chk.c基本上是从GNU C库中来的:

#include <sys/select.h>

# define strong_alias(name, aliasname) _strong_alias(name, aliasname)
# define _strong_alias(name, aliasname) \
  extern __typeof (name) aliasname __attribute__ ((alias (#name)));

unsigned long int
__fdelt_chk (unsigned long int d) …
Run Code Online (Sandbox Code Playgroud)

glibc dynamic-linking ld fortify-source

17
推荐指数
2
解决办法
8454
查看次数

由<iterator>引入的sys/sysmacros.h中定义的主要和次要宏

我正在编写一个具有类似矩阵结构的类,我希望有一个名为minor的成员函数与矩阵操作相同.这会触发一些错误.我系统上的最小测试用例:

#include <iterator>
void minor(int row, int col);
Run Code Online (Sandbox Code Playgroud)

编译时,clang提供以下错误:

$ clang++ -Weverything -std=c++11 test.cpp 
test.cpp:2:21: error: too many arguments provided to function-like macro invocation
void minor(int row, int col);
                    ^
/usr/include/x86_64-linux-gnu/sys/sysmacros.h:67:10: note: macro 'minor' defined here
# define minor(dev) gnu_dev_minor (dev)
         ^
test.cpp:2:6: error: variable has incomplete type 'void'
void minor(int row, int col);
     ^
2 errors generated.
$
Run Code Online (Sandbox Code Playgroud)

sys/sysmacros.h的相关部分是:

/* Access the functions with their traditional names.  */
# define major(dev) gnu_dev_major (dev)
# define minor(dev) gnu_dev_minor (dev)
# …
Run Code Online (Sandbox Code Playgroud)

c++ macros glibc libstdc++

17
推荐指数
1
解决办法
4815
查看次数

RHEL 6 - 如何安装'GLIBC_2.14'或'GLIBC_2.15'?

我需要在RHEL 6 linux系统上安装这两个软件包.其他几个项目都需要它们.

当我做:

sudo yum install glibc-devel
Run Code Online (Sandbox Code Playgroud)

这是输出:

Loaded plugins: product-id, security
Setting up Install Process
Package glibc-devel-2.12-1.166.el6_7.1.x86_64 already installed and latest version
Nothing to do
Run Code Online (Sandbox Code Playgroud)

对于RHEL,是否有一些EPEL与GLIBC_2.15?如果不是 - 这里的解决方法是什么?

dependencies glibc rhel yum

17
推荐指数
2
解决办法
8万
查看次数