Questions tagged [libc]

The C standard library consists of a set of sections of the ISO C standard which describe a collection of headers and library routines used to implement common operations, such as input/output and string handling, in the C programming language.

Filter by
Sorted by
Tagged with
1
vote
1answer
53 views

Statically linking libc into my binary causes it to segfault

I need to build a binary with libc statically linked. I have libc.a available in the same directory as the source code. To compile, I tried the following: gcc -o foo foo.c libc.a This resulted in ...
1
vote
1answer
33 views

Do internal libc function calls have to go through .plt

A program linked against libc.so calls a libc function through the plt, let's say setenv(). Internally within setenv() it calls malloc(), at least according to musl libc. Does the setenv()->malloc() ...
0
votes
0answers
33 views

return to libc attack

I"m trying to learn about the return to libc attack. I have to following c program: #include <stdio.h> #include <unistd.h> void sayHello(char *stri) { char bufferx[999]; strcpy(...
-1
votes
0answers
31 views

How to debug `chmod()` system call?

I have a process (written in Rust) running as root (started as a systemd service), on a Linux machine (ubuntu 18.04, x86-64), the process calls the chmod() system call (via libc::chmod()) with mode ...
0
votes
0answers
22 views

Writing and implementing libc for an operating system

I was getting in to os development lately and I wanted to implement a C standard libary, so I can write more easily software for it and figure out how everything fits together. I was looking for some ...
-1
votes
2answers
31 views

What standard C library does Clang use? glibc, its own, or some other one?

I'm pretty sure glibc is the name of the standard C library implementation for gcc. But for LLVM/Clang I'm not sure. I've Googled to try to find if it comes with its own implementation of the whole ...
0
votes
0answers
33 views

Implement own read() system call using pread()

this question is somewhat related to another question I posted before (I'm posting this here as a new question, as I didnt wanted to interrupt the ongoing discussion in the other thread). I'm trying ...
5
votes
1answer
97 views

Why does fseek use read() system call?

I'm trying to understand the glibc implementation of fseek. To do so, I downloaded the glibc source code and tried to understand its function execution order. I found the fseek implementation in ...
2
votes
0answers
25 views

cmake - building target with custom compile options [duplicate]

I'm trying to to build a project (https://github.com/UWQuickstep/quickstep) which seems to use cmake, against newly compiled glibc installed in a different location (https://sourceware.org/glibc/wiki/...
0
votes
0answers
34 views

Using ioctl with C#

I'm trying to use an orangePi spi via C#. There's a code sample in C below. I can import open/ioctl methods using the C# DllImport attribute. But I don't know how to get SPI_IOC_WR_MODE / ...
0
votes
0answers
15 views

How to compile program with older version of GLIBC? [duplicate]

When I'm trying to launch cross-compiled program on target system, I get error: libc.so.6: version 'GLIBC_2.29' not found (required by MyProg) How can I solve this problem? Maybe I have to cross-...
0
votes
1answer
24 views

How does LD_PRELOAD update the library function

I know we can use the LD_PRELOAD trick to replace a libc function, e.g., malloc(). So how exactly LD_PRELOAD works? Does it replace the GOT/PLT entry?
0
votes
1answer
58 views

OpenCascade compilation failure on Alpine linux with musl libc (mallinfo: has initializer but incomplete type error)

I'm trying to compile OpenCascade (OCE) with g++/gcc on Alpine Linux. It builds fine on Ubuntu but the same project fails on Apline with the errors: OSD_MemInfo.cxx: In member function 'void ...
0
votes
1answer
68 views

How can I create a static executable with rustc using glibc instead of musl?

I wrote simple code in C, Go and Rust. foo.c #include <stdio.h> int main() { printf("hello\n"); return 0; } foo.go package main import "fmt" func main() { fmt.Println("hello");...
4
votes
1answer
51 views

libc include guards not respecting source type parameter changes

Question If I include time.h, change a "source type parameter" and re-include that header, shouldn't it add in those new definitions? I understand that this is happening due to include guards. My ...
0
votes
1answer
27 views

fopen failed when using wasi-libc

I tried to use fopen to read an image when using wasi-libc: #include <stdio.h> int main() { FILE *f = fopen("test.png", "rb"); printf("file %p\n", f); fclose(f); } Build the code ...
1
vote
0answers
29 views

Compiling an LD_PRELOAD hook to use in a chroot

I know that usually we don't want to have a static linking to libc for compatibility reasons, but I have an application that will run inside a Docker, and using LD_PRELOAD will gain execution to hook ...
0
votes
0answers
14 views

Using two different libcs at the same time

my situation is that I created a compile time instrumentation system that inserts code in an application that does some book-keeping of it's internal state for dynamic analysis purposes. The injected ...
0
votes
1answer
73 views

Why don't 64-bit systems have syscalls like creat?

From this commit https://github.com/torvalds/linux/commit/a0673fdbcd42105261646cd4f3447455b5854a32 I learnt that there are some 32bit-spec syscalls like creat, which have been removed on ...
0
votes
1answer
29 views

Problem with sprintf and uint64_t (avr-libc 2.0.0)

I am playing with the function sprintf in avr-libc 2.0.0 and uint64_t, and it seems it doesn't work properly. The code uint64_t x = 12ull; char buffer[30]; int len = sprintf(buffer, "%llu", x); int ...
0
votes
1answer
77 views

How do I open a file with the flags provided as an i32 matching the C open function?

I need to open a file and I have a &Path and an i32 for the flags. I can open files with File::open(path), but this won't let me set the options. The documentation says I should use OpenOptions, ...
0
votes
0answers
45 views

Little/big endian integer types in user space

I'm going to use struct solaris_x86_slice from linux kernel header in user space. Struct is defined as: struct solaris_x86_slice { __le16 s_tag; /* ID tag of partition */ __le16 s_flag; ...
1
vote
0answers
38 views

Locally built GCC cross-compiler reports MB_LEN_MAX wrong with -D_FORTIFY_SOURCE=2

I am currently building a cross-compiler targeting the PowerPC architecture. It is capable of building Linux binaries that work and can execute on the target, however I hit a problem when I enable the ...
1
vote
1answer
56 views

How are system calls called?

So I understand what system calls are for and what they do. Pretty much anything that requires a computer's resources invokes a system call at some point. My question is, how does a user-created ...
0
votes
1answer
29 views

GCC fails to link to libc.a

I am compiling a project with multiple libraries without issue. I am using stdlib content. However, math.h functions are failing to link. My command line compilation is as follows: gcc -o exe/...
4
votes
1answer
170 views

What is the purpose of glibc's atomic_forced_read function?

I am trying to understand the purpose of the definition of atomic_forced_read which shows up frequently in the GNU libc implementation of malloc.c. I am not great when it comes to inline assembly, ...
8
votes
3answers
140 views

What is “namespace cleanliness”, and how does glibc achieve it?

I came across this paragraph from this answer by @zwol recently: The __libc_ prefix on read is because there are actually three different names for read in the C library: read, __read, and ...
0
votes
2answers
88 views

Call libc function from assembly

I have a function defined in assembly that is calling a libc function (swapcontext). I invoke that function from my C code. For the purpose of creating a reproducible example, I'm using 'puts' instead:...
3
votes
5answers
131 views

What is the behaviour of `ferror(FILE *)` and `std::ferror(FILE *)` when passed invalid pointers?

What is the behavior of ::ferror(FILE *) and std::ferror(FILE *) when passed invalid pointers? The C++ standards just refer to C (see draft). But in the C standard there is no mention under the ...
1
vote
1answer
85 views

libc crate doesn't provide sprintf on Windows

I wrote a library in Rust that uses C formatting using the sprintf function provided by the libc crate. Everything works on macOS and Linux but it does not compile on Windows because the sprintf ...
1
vote
1answer
73 views

libstdc++.so not found when using patchelf and alternate glibc version

I am working on a system with a system wide glibc 2.27 and am using pathelf to patch some executable to a customized version of glibc 2.23. The executables are compiled with a custom version of LLVM. ...
0
votes
1answer
20 views

Does process linking still load o files in libc.a?

I am looking at this lecture note (slide #6): file.o contains external symbols and defined symbols libc.a contains .o files for all library functions. Process of linking: scan libc.a for symbols ...
0
votes
0answers
37 views

printfs hangs in kubernetes environment

I am debugging an app for a hang. This is running as a container in the kubernetes environment. The app is multi threaded and implements a fuse file system. Thread 7 (Thread 0x7f631da4d700 (LWP 20))...
0
votes
0answers
28 views

memmove in osdev meaty-skeleton: why does it have these if/else statements? [duplicate]

In the os-dev meaty skeleton tutorial this is the implementation of memmove: #include <string.h> void* memmove(void* dstptr, const void* srcptr, size_t size) { unsigned char* dst = (...
2
votes
1answer
314 views

installing `libm.so.6` through Anaconda

I have a centOS machine that I do not have sudo access. I needed to use librosa python package so I have installed Anaconda and installed the package through conda. However, when I import this ...
3
votes
1answer
63 views

How to find the maximum value(s) in a RB tree

I'm working on a project which requires me to create and frequently search a RB tree using the glibc functions found in search.h. I have no problem creating the tree nor searching it; however, I just ...
1
vote
1answer
550 views

Fatal Signal on Launch (KitKat)

I've been receiving the following error on KitKat but there are no issues on Android M and above : 2145-2145/com.cafeapps.stroydownloader E/dalvikvm: Could not find class 'com.crashlytics.android.ndk....
0
votes
0answers
31 views

would it be safe to get the length of arguments with strlen? [duplicate]

I want to get the length of command-line arguments but I'm not sure if strlen is a secure solution. strlen works as intended, but apparently it's not secure since the string being measured may not be ...
1
vote
1answer
64 views

Is it possible to check whether a C macro is defined on your system in Rust?

I'm aware that the libc crate in Rust contains much of C's standard macros and functions for use in Rust, but it also states that it is not concerned with portability between systems. I'm porting some ...
3
votes
1answer
181 views

How to include (msvc) libc when building c code with the Zig compiler

I've recently discovered zig and find it very interesting. I'm now trying to learn how to use zig as a cross compiler and, the following builds and runs fine (on Windows) zig cc -Wno-everything src/...
2
votes
2answers
91 views

Understanding the gcc version and the GLIBC, GLIBCXX versions in more detail

Assume I have the following local gcc, g++ version: $ gcc -v $ g++ -v gcc version 6.3.1 I don't understanding the relation and meaning of the following compared to my compiler version: What is this ...
3
votes
1answer
161 views

React native 0.59 application crashes with libc error

I'm having the following problem on [email protected] It happens randomly on some screens in the app. any idea what would cause this? should I open a bug report in the react-native repo? Here is ...
1
vote
0answers
24 views

cross-plat version of _wfullpath()

is there a cross platform version of _fullpath() which is windows specific function? looking for a portable library function for this. tried realpath() but this is supported for linux and Mac but not ...
2
votes
1answer
91 views

How to find out which files are being linked with “-lc”?

After spending almost an hour on filtering output of clang -v hello_world.c I got the following linking command: ld -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 \ /usr/lib/x86_64-linux-...
4
votes
2answers
173 views

How does the libc function isatty() work?

I searched the linux repo and couldn't find a definition for it, so I guess it's something that comes with C or something like that? I'm trying to understand how isatty is able to tell whether a file ...
5
votes
2answers
143 views

fgets(), signals (EINTR) and input data integrity

fgets() was intended for reading some string until EOF or \n occurred. It is very handy for reading text config files, for example, but there are some problems. First, it may return EINTR in case of ...
2
votes
1answer
82 views

What happens when two or more threads or processes ftruncate(2) the same file?

As far as I understand, ftruncate(2) can't be atomic when I am expanding a file upto 2 GB length. But what exactly happens behind the scenes? I have applied it and it seems to work fine when more ...
1
vote
1answer
82 views

ImageMagick Error: “corrupted size vs. prev_size” in libc.so on Linux

I am using imagemagick 7 to read and write some TIFF files. I have C++ code to do the same and it is working fine with windows. I am facing this issue while writing TIFF file on Linux. I magemagick is ...
1
vote
2answers
189 views

How to avoid multiple definitions? Linker ignored defined symbol with some exception

I am working on an embedded system which has its own library (e.g. libc_alt ) implementing some functions from standard libc (fopen, fclose, fread, fseek, ftell) but not all ( I need memset, memcpy, ...
0
votes
1answer
39 views

Modify compile steps of glibc

I am trying to recompile the standard Glibc 2.20, with a requirement that I disable optimizations for a few specific components. In particular, I'm looking to remove the -O2 flag that's inherited from ...