x86-64

How to compile my own glibc C standard library from source and use it?

柔情痞子 提交于 2019-11-30 07:04:54
I am trying to compile my own glibc. I have a directory glibc , which contain the glibc source code I downloaded from the internet. From that directory I typed mkdir ../build-glibc . Now from the build-glibc directory I typed ../glibc/configure , which performed the configuration. Now I'm not sure how to call make . I can't call it from glibc directory since it doesn't have the configuration set, neither I can call it from build-glibc , since makefile is not in that directory. How do I solve this problem? The Makefile is going to exist in your build-glibc directory if the configure script

Basic OS X Assembly and the Mach-O format

左心房为你撑大大i 提交于 2019-11-30 07:01:20
问题 I am interested in programming in x86-64 assembly on the Mac OS X platform. I came across this page about creating a 248B Mach-O program, which led me to Apple's own Mach-O format reference. After that I thought I'd make that same simple C program in Xcode and check out the generated assembly. This was the code: int main(int argc, const char * argv[]) { return 42; } But the assembly generated was 334 lines, containing (based on the 248B model) a lot of excess content. Firstly, why is so much

How to load a pixel struct into an SSE register?

时光总嘲笑我的痴心妄想 提交于 2019-11-30 06:57:54
I have a struct of 8-bit pixel data: struct __attribute__((aligned(4))) pixels { char r; char g; char b; char a; } I want to use SSE instructions to calculate certain things on these pixels (namely, a Paeth transformation). How can I load these pixels into an SSE register as 32-bits unsigned integers? Unpacking unsigned pixels with SSE2 Ok, using SSE2 integer intrinsics from <emmintrin.h> first load the thing into the lower 32 bits of the register: __m128i xmm0 = _mm_cvtsi32_si128(*(const int*)&pixel); Then first unpack those 8-bit values into 16-bit values in the lower 64 bits of the register

Syscall from inline asm in x86_64 Linux?

和自甴很熟 提交于 2019-11-30 06:54:58
Why does this print garbage instead of exiting my program gracefully? I use system calls this way on BSD, and I wonder what would I need to make it work in Linux. int main(int argc, char **argv) { __asm ("movq $1,%rax; movq $0,%rdi; syscall"); /* exit(0) ? */ return 0; } Thanks. Why does this print garbage instead of exiting my program gracefully? Per CESA-2009-001 , "Syscall 1 is exit on i386 but write on x86_64". what would I need to make it work in Linux Use the syscall ordinals from the current unistd_64.h Hope this helps! Syscall 1 is exit on i386 but write on x86-64 I believe. EDIT: this

Prefetching data to cache for x86-64

冷暖自知 提交于 2019-11-30 06:43:59
In my application, at one point I need to perform calculations on a large contiguous block of memory data (100s of MBs). What I was thinking was to keep prefetching the part of the block my program will touch in future, so that when I perform calculations on that portion, the data is already in the cache. Can someone give me a simple example of how to achieve this with gcc? I read _mm_prefetch somewhere, but don't know how to properly use it. Also note that I have a multicore system, but each core will be working on a different region of memory in parallel. gcc uses builtin functions as an

Examining C/C++ Heap memory statistics in gdb

谁说胖子不能爱 提交于 2019-11-30 06:29:52
问题 I'm trying to investigate the state of the C/C++ heap from within gdb on Linux amd64, is there a nice way to do this? One approach I've tried is to "call mallinfo()" but unfortunately I can't then extract the values I want since gdb doesn't deal with the return value properly. I'm not easily able to write a function to be compiled into the binary for the process I am attached to, so I can simply implement my own function to extract the values by calling mallinfo() in my own code this way. Is

Under what conditions do I need to set up SEH unwind info for an x86-64 assembly function?

馋奶兔 提交于 2019-11-30 04:55:07
问题 The 64-bit Windows ABI defines a generalized exception handling mechanism, which I believe is shared across C++ exceptions and structured exceptions available even in other languages such as C. If I'm writing an x86-64 assembly routine to be compiled in nasm and linked into a C or C++ library, what accommodations do I need make on Windows in terms of generating unwind info and so on? I'm not planning on generating any exceptions directly in the assembly code, although I suppose it is possible

CMake -G Ninja on Windows specify x64

隐身守侯 提交于 2019-11-30 04:53:39
I am using CMake on Windows with Ninja generator cmake -G Ninja .. This uses the default Windows x86 toolchain. How to specify x64 using the Ninja generator? PS: I know how to generate x64 with Visual Studio cmake -G "Visual Studio 12 2013 Win64 .. You have to set the compiler environment accordingly before calling Ninja generation. If you have Visual Studio 2013 installed at the standard installation path you call: "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x64 cmake.exe -G "Ninja" .. Edit : Thanks for the hint from @Antwane: "Or simply run CMake command from a

Is increment an integer atomic in x86? [duplicate]

本秂侑毒 提交于 2019-11-30 04:52:22
This question already has an answer here: Can num++ be atomic for 'int num'? 13 answers On a multicore x86 machine, Say a thread executing on core1 increments an integer variable a at the same time thread on core 2 also increments it. Given that the initial value of a was 0, would it always be 2 in the end? Or it could have some other value? Assume that a is declared as volatile and we are not using atomic variables (such as atomic<> of C++ and built in atomic operations in gcc). If the value of a would indeed be always 2 in such event, does that mean that a long int in x86-64 would also have

Injecting code into executable at runtime

Deadly 提交于 2019-11-30 04:01:54
I'm working on application (written in C++), which generate some machine code at runtime (Linux, x86-64 now, but I plan to migrate on ARM). Next it store generated code in memory and execute it by jumping to memory location. For a long time I had a problem with allocating executable memory, but I finally solved it using: uint8_t *memory = mmap (NULL, length, PROT_READ | PROT_WRITE | PROT_EXEC, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); So far it works, but I'm not sure if it's elegant way to do such things. I wonder how executable loader do this? This is essentially how executable loaders do things;