1,138 questions
3
votes
2
answers
1k
views
Is stat(2) thread safe?
Many functions of the C library are clearly marked as thread-safe or not thread-safe. For example, when I look at the manual of gmtime(3) there is a nice table that shows which of these functions are ...
2
votes
1
answer
359
views
Does getppid Refers to Parent OR Real Parent?
I'm confused about the getppid syscall in linux.
Does it return the pid of the process that spawned it or the current parent (which could be different if the original parent exited)?
3
votes
0
answers
844
views
How would I set a thread priority in Rust in macOS?
The crate thread-priority is only supported on Windows and Linux operating systems but unfortunately isn't supported for macOS. So the only crate I found that would support macOS was libc but it lacks ...
0
votes
1
answer
967
views
How to print the content of a text file to STDOUT in Linux Assembly Language using c library functions?
First I tried opening a file with fopen function and print content of the file using fprint function but it was just printing a bunch of symbols to the terminal.
After a while I realized that it does ...
2
votes
1
answer
353
views
How to use shared library from Android on Raspberry Pi
I have closed-source shared library originally built for Android which I want to use on Raspberry Pi. The problem is this:
/usr/bin/ld: /usr/lib/libfoo.so: undefined reference to `__cxa_atexit@LIBC'
/...
3
votes
1
answer
904
views
no implementation of __fpclassify in armhf
I'm cross-compiling for Raspberry Pi 4B using ARM's 10.3-2021.07 GCC toolchain (specifically this file uncompressed into ARMGCC). I'm also using the latest Raspberry OS image as sysroot (loop-mounted ...
3
votes
1
answer
83
views
Stack arguments are disappearing in assembly using C calling convention
I am currently writing a bit of x86 assembly code and linking it with glibc using as and ld.
.section .data
str1:
.asciz "\n"
str3:
.asciz "Hello"
str4:
.asciz &...
33
votes
2
answers
3k
views
Are symbols from the C standard library reserved in C++?
This is a follow-up to a different question.
The original question had other problems but I had to realize that the main one (according to CLang) was a redefinition of time as a different symbol while ...
-1
votes
2
answers
788
views
C++ print time difference?
In C++ I wrote:
time_t tmp1, tmp2;
time(&tmp1);
sleep(1);
time(&tmp2);
std::cout << tmp2-tmp1;
But every-time I run it I see 1 printed, why the result is too perfect? shouldn't it ...
2
votes
0
answers
372
views
how build and install "mlibc" with and for a gcc cross-compiler?
I wanna create a gcc cross-compiler. I work on a WSL2 ubuntu 20.04 distrib and the target will be x86_64-elf ( for a bare metal project ).
For this learning project, I need to build a C libray with ...
0
votes
1
answer
674
views
Executable not linking to the my desired dynamic library
I have built and installed mpich from source (mpich-3.4.1.tar.gz), using the steps given in 'https://www.mpich.org/static/downloads/3.4.1/mpich-3.4.1-README.txt'. I want the resultant executables to ...
2
votes
0
answers
72
views
Wrapping malloc using the LD_PRELOAD trick [duplicate]
My goal is to wrap malloc() with my own implementation and then inject that implementation into executables using LD_PRELOAD trick for educational purposes.
I've made two files, test.c for testing the ...
1
vote
1
answer
743
views
perf record with --call-stack fp fails to unwind main function
I have a C++ test program that keeps the CPU busy:
#include <cstdint>
#include <iostream>
// Linear-feedback shift register
uint64_t lfsr1(uint64_t max_ix)
{
uint64_t start_state = ...
1
vote
1
answer
843
views
Get C FILE pointer from bytes::Bytes in Rust
I would like to read a GRIB file downloaded from server using ecCodes library in Rust. However, my current solution results in segmentation fault. The extracted example, replicating the problem, is ...
0
votes
1
answer
217
views
Circular reference between libc.so.6 and liblsp.so?
▶ldd /lib/x86_64-linux-gnu/libc.so.6
linux-vdso.so.1 (0x00007fff2b856000)
/lib/$LIB/liblsp.so => /lib/lib/x86_64-linux-gnu/liblsp.so (0x00007f472effc000)
/lib64/ld-linux-x86-...
3
votes
1
answer
275
views
libc::recv does not return on docker
I wrote a simple packet capture in Rust on docker hosted by macOS.
However, libc::recv doesn't return forever.
src/main.rs
use std::io;
fn main() -> io::Result<()> {
let sock = unsafe {
...
1
vote
1
answer
206
views
Segmentation Fault when call iswctype function in libc.so.6 using python ctypes
I'm learning ctypes module in python. I have the following code:
code
import sys
print(sys.version)
import ctypes
libc = ctypes.CDLL("/lib/x86_64-linux-gnu/libc.so.6")
print(libc)
for x in &...
0
votes
1
answer
330
views
How to implement crypt() and wordexp.h in Android Posix
I know that these 2 functionalities are not provided by Bionics libc implementation. I do need these for a C++ to Android port. How can I solve this problem? I dont know where to start here.
I get ...
3
votes
1
answer
327
views
Portable alternative to execvpe
The execvpe function is a GNU extension. If I want my code to e portable to non-gnu libcs, how can I change an execvpe call to be portable?
execvp doesn't set the environment of the new program, and ...
5
votes
0
answers
289
views
errno without thread-local storage
I want to statically compile a program with tcc. tcc complains with error: Unknown relocation type: 23. This is apparently caused by my libc implementation (glibc 2.28-10) using thread-local storage ...
1
vote
0
answers
168
views
Override libc open() result in python os.popen().read() hangs
I override the libc open() function like this and compile it to a shared library called libc_custom.so:
struct sys_funcs_t
{
sys_funcs_t()
{
libc_hdl = dlopen("/usr/lib64/libc.so....
1
vote
1
answer
1k
views
libc syscall(), benefits from passing call number?
The man page for syscall says that the first argument is the system call number.
On my system (linux x64), arguments are sent in rdi, rsi, rdx, rcx, r8 and r9.
So, rdi receives the call number.
The ...
-1
votes
1
answer
871
views
How to let ld use PIC version of libc.a
To link gcc statically into a shared library, based on the answer in this question, the remaining problem is how to let the linker use the PIC version of libc.a instead of the non-PIC version. The ...
2
votes
1
answer
488
views
MT and MD on Linux
I'm curious why there is so much about MT and MD on Windows and no-one is talking about linux. In linux, afaik, there is the libc.so as the MD equivalent, and the libc.a as the MT equivalent.
Since ...
2
votes
0
answers
110
views
time() not using vdso?
I write a program,use time() function,
When I gdb it :
[VM_241_149_tlinux ~/test]$ gdb ./testsys_d -q
Reading symbols from /data/home/youngxiao/test/testsys_d...(no debugging symbols found)...done.
(...
2
votes
1
answer
3k
views
Managed to leak puts function address in libc, but unable to get addresses of other functions
I am currently learning about binary exploitation. Now i am working with a binary (Linux) that is vulnerable to a stack buffer overflow (ASLR and NX are enabled, and binary is interacted with through ...
1
vote
1
answer
706
views
Can multiple shared libaries used by a program use different static linked libc?
On Windows this can be done (though not recommended since pass c standard library object between different c library instances can have problem), like this:
Every executable image (EXE or DLL) can ...
3
votes
0
answers
327
views
What does "bits" directory stand for in glibc project?
I found out headers under "bits" directory are internal headers which general headers include.
Then what does the name "bits" stand for?
1
vote
1
answer
2k
views
What is glibc and POSIX exactly?
I am really confused. Please look at the following picture:
I found out that there is a library in linux called glibc, which when we execute our c/c++ programs we use its functions and it calls the ...
27
votes
2
answers
4k
views
What is the purpose of libc_nonshared.a?
Why does libc_nonshared.a exist? What purpose does it serve? I haven't been able to find a good answer for its existence online.
As far as I can tell it provides certain symbols (stat, lstat, fstat, ...
0
votes
0
answers
613
views
Error while building Glibc 2.25 on Ubuntu 20.04
I'm trying to build Glibc 2.25 on an Ubuntu 20.04 machine and using the build instructions given here : https://sourceware.org/glibc/wiki/Testing/Builds#Building_glibc_with_intent_to_install
I'm ...
0
votes
1
answer
858
views
getrlimit -1 return value
While creating different benchmarks I often aim for the best latency. As you all know, memory in the heap is much more expensive to access than on the stack. We are now in 2021 and when I try ulimit -...
6
votes
1
answer
275
views
What is this implementation of fread in Chromium OS made of?
I was looking at the source code of fread in chromium-os / glibc and became increasingly puzzled about it.
NB: I am talking about the source code and NOT the use of fread or other related questions
...
2
votes
2
answers
269
views
Check for out of memory error on open_memstream's FILE operation
Does POSIX guarantees the ferror is set on open_memstream's FILE write operations?
How do I check for out of memory condition on FILE operation if the FILE is created with open_memstream?
I used to ...
4
votes
1
answer
11k
views
Installing libc6 2.33 on debian
I would like to install libc6 2.33 onto a debian docker container for security patch reasons. I can see here that it has been released, and also it is noted here that 2.33 is available.
Is there any ...
2
votes
1
answer
1k
views
C++ multi-thread memory leak issue
Once the following code is running, it will eat all my memory and cause OOM issue on my ARM 64-bit processor. it seems that some 'delete' operations do not work... it confused me. Could any experts ...
1
vote
1
answer
1k
views
Change default file descriptor for Rust print functions
I'm working on Rust and using a shared library written in C++. The problem that the C++ library spawns a few threads that constantly print to stdout (1) and that interferes with my own logging.
I was ...
1
vote
1
answer
802
views
Why does my C strlen() in Rust also count string slice inside print! macro after `s` variable?
So i was just tinkering with C libs in Rust and i found that the following code:
extern crate libc;
use libc::{c_char, c_int, size_t};
extern "C" {
fn printf(fmt: *const c_char, ...) -&...
4
votes
0
answers
4k
views
how to install debug info for libc?
ADD : This link (https://stackoverflow.com/a/48287761/2554472) had the answer for my question (Mark Plotnick's answer). Different title, duplicate answer.
I'm using ddd(with gdb) to analyze a program(...
0
votes
0
answers
151
views
Reread file after fseek to beginning?
I have this test program:
#include "stdio.h"
int main()
{
FILE* read;
FILE* write;
write = fopen("file.txt", "w");
fwrite("Hallo", 1, 6, write);
...
3
votes
2
answers
3k
views
atom libc-2.31.so segfault in ubuntu 18.04
atom worked smoothly in my Dell Latitude 5410 running Ubuntu 18.04. Suddenly it won't open and looking at tail -F /var/log/syslog I got a libc-2.31.so segfault:
Jan 15 03:22:17 enrico-dell-latitude-...
0
votes
1
answer
2k
views
How can I fix the length of a string in printf when called from RISC-V assembly?
I want to get some output on a RISC-V program (assembly) running on top of pk on Spike using newlib.
I can call printf with null terminated strings eg (snippet)
la a0 msg_
jal printf
.data
msg_ ....
7
votes
1
answer
450
views
Do any functions in the C standard library implicitly use `stderr`?
The C spec mandates all C programs have 3 streams open and available to them: stdout, stdin, stderr.
The users can use these streams as they see fit, e.g.:
fprintf(stdout, "lol");
fputs(&...
1
vote
1
answer
640
views
cross compiling libc for x86_64-linux-android
I am cross compiling (using x86_64-linux-android-gcc) to build GNU libc, GLIBC version 2.32, for x86_64-linux-android. Getting the error "inconsistent operand constraints in an __asm" from ...
8
votes
2
answers
3k
views
Can a system call happen in a C program? [duplicate]
Can a system call happen in a C program?
Consider this:
int main()
{
int f = open("/tmp/test.txt", O_CREAT | O_RDWR, 0666);
write(f, "hello world", 11);
close(f);
...
8
votes
1
answer
4k
views
How to fix llvmlibc-restrict-system-libc-headers check in Clang Tidy?
I do not understand the llvmlibc-restrict-system-libc-headers check in Clang Tidy (link).
I include C libraries in C++ code like this:
#include <cstddef>
What should I change to fix this Clang ...
0
votes
1
answer
283
views
What is the structure of libc.so.6 time.c
Okay, I give up. I can't read C for my life!
What is the structure of time_t below?
/usr/include/bits/types/time_t.h
#ifndef __time_t_defined
#define __time_t_defined 1
#include <bits/types.h>...
7
votes
1
answer
9k
views
VS Code remote ssh missing GLIBCXX and GLIBC
I am trying to use the remote development via ssh feature of VS Code. When connecting to the remote server I encounter:
Missing GLIBCXX >= 3.4.18!
>Found versions 3.4.1
> 3.4.2
> ...
> ...
2
votes
1
answer
1k
views
What happens if I realloc to smaller size?
I'm currently studying dynamic memory allocation and I've got a question on realloc function.
I've learned that the contents of the newly allocated block should be same as those of the old block, up ...
1
vote
0
answers
242
views
autoconf detecting where pthread functions really are
I'm looking for a way to detect where pthread functions really exist (libc, libpthread or both). My motivation is that GNU libc seems to be moving the pthread functions from libpthread to libc. I need ...