How to distinguish syslog(2) and syslog(3)? - gcc

I see that there are syslog(2) and syslog(3).
https://man7.org/linux/man-pages/man2/syslog.2.html
https://man7.org/linux/man-pages/man3/syslog.3.html
Since they have the same function time, I don't see how the linker can distinguish them at link time. Could anybody help me understand how the linker correctly resolve the object code under the hood? Thanks.

It doesn't.. syslog(2) has to be called using klogctl() wrapper or using syscall() at your own peril.. syslog(3) is the only definition present in the C library.

Related

Lua - Is there a different function in the Lua library that is identical or similar to debug.getupvalues / debug.getupvalue?

Is it possible or is there a function that works similar to debug.getupvalues / debug.getupvalue in the lua library that I could use, as I won't be able to use either soon and I depend on them slightly to keep parts of the code I have working.
Also if I could get the function code for debug.getupvalue it would be a great help as I could just use that as a function instead of using the debug library anymore, although I doubt it is code in Lua.
And before you say it, yes I know the debug library is the most undependable library in all of Lua but it made my code work and I would like to find a way to stop using it before it's too late.
The debug library is not meant to be used in production code (as opposed to tests and unusual debugging situations). There are 3 possible solutions. Two of them require changes to the code where the closures are defined. The other would require you to know C:
Add more closures in the same scope as the upvalues that will give you the access that you need.
Use tables instead of closures.
Write a C library that makes use of lua_getupvalue.
To see the source code of debug.getupvalue, download Lua 5.3.5 and look at src/ldblib.c, line 260. lua_getupvalue is in src/lapi.c, line 1222.

How is is_standard_layout implemented?

In general one can implement typical type_traits using template techniques.
However I didn't imagine how std::is_standard_layout could be implemented in these terms. http://en.cppreference.com/w/cpp/types/is_standard_layout
When I checked the gcc standard library, I found that it is implemented in terms of __is_standard_layout(T) which I could not find defined anywhere else. Is this a compiler magic function?
Would it be possible to implement std::is_standard_layout explicitly?
For example one of the conditions is that it inherits from a single class.
That seems to be impossible to determine at compile time.
No, std::is_standard_layout is not something you can implement without compiler intrinsics. As you've correctly pointed out, it needs more information than the C++ type system can express.

Where is append() implementation?

I cannot find implementation code of append() or any other builtin functions anywhere? I tried finding the code through godoc and using jump-to-definition feature of IDE's. May be i am looking at wrong places. Could anyone show me the way to see actual implementation?
You may be interested by :
the code generating bit append is in here https://github.com/golang/go/blob/go1.16.7/src/cmd/compile/internal/gc/ssa.go
and growslice, used by the former, and that lives in here : https://github.com/golang/go/blob/go1.16.7/src/runtime/slice.go

Rust library for inspecting .rlib binaries

I'm looking for a way to load and inspect .rlib binaries generated by rustc. I've hunted around the standard library without much luck. My assumption is that an .rlib contains all the type information necessary to statically type check programs that "extern crate" it. rustc::metadata is where my hunt ended. I can't quite figure out if the structures available at this point in the compiler are intended as entry points for users, or if they are solely intermediate abstractions depending on a chain of previously initialized data.
Alternatively, If there's a way to dump an .rlib to stdout in a parsable form then that's also fantastic. I tried /usr/bin/nm, but it seemed to be excluding function type signatures. Maybe I'm missing something.
Anyways, I'm working on an editor utility for emacs that I hope at some point will provide contextually relevant information such as available methods, module items and their types, etc. I'd really appreciate any hints anyone has.
The .rlib file is an ar archive file. You can use readelf to read its content.
Try readelf -s <your_lib>.rlib. The type name may be mingled/decorated by the compiler so it may not be exactly the same as in .rs file.

C++ defining IAT manually

I just changed from (F)ASM to C and saw that I get for a MessageBox 25kb (vs 3kb). I just included windows.h, but I see that windows.h includes about 22kb that I don't need ;).
At ASM I'm able to define the IAT (Import Address Table) and this I want to do with the GCC to reduce the oversized executable.
SO does anyone know how I can do this? Is it possible?
PS: If you know a solution for an other compiler please post it too (then I'll use the other one).
OK because I can't find any way to do it, I read about shell code (which has to be small and position independend).
harmonysecurity.com wrote about this and so I would solve my problem with inline-ASM.
This is the blog.
I hope that helps.

Resources