5 ms·
All this assembly tricks are interesting but not really useful in real production code. Part about the struct packing is quite common and used but I don’t unde
by nokeya 2y ago
All this assembly tricks are interesting but not really useful in real production code. Part about the struct packing is quite common and used but I don’t understand why these extra paddings are present and why one is gone. Even with pragma pack 8, should not it be only one padding?
- stevekemp 2y agoI suspect it depends upon your niche/field, there are certainly times when I've done assembly coding for production. Although I admit these days most of my assembly-coding is for retro-uses.
- kabdib 2y agoi work on embedded systems, and this stuff does matter. it costs real money when you are buying the chips and selling hardware
- Just_Harry 2y ago> I don’t understand why these extra paddings are present and why one is gone. Even with pragma pack 8, should not it be only one padding? If you're referring to `__pad2` in the example, that trailing padding is there to ensure that the size of the struct is a multiple of its alignment, which is 8, so that if there's a contiguous span of those structures, each instance after the first one will remained properly aligned. Without `__pad2`, that struct would be 36-bytes, which would cause every other instance in an array/contiguous-span to be aligned on 4 bytes instead of 8.
- bluetomcat 2y ago> but I don’t understand why these extra paddings are present and why one is gone In the example from the article, the "s_arc" member is a pointer (8 bytes) and requires an alignment at an 8-byte boundary. The ints are 4 bytes in size. The whole struct needs to be aligned on an 8-byte boundary, in order to preserve the alignment requirements of the pointers. The trailing "s_accept" member requires additional padding to make the size of the struct divisible by 8, and that would preserve the alignment of an eventual second adjacent struct, when having an array of these structs.
- vardump 2y agoOne day you might have to patch a binary with a hex editor. For reason or another.
- tjalfi 2y agoAt my last job, I had to patch a binary for one of our internal .NET applications. The application was hardcoded to connect to a specific database, but we needed it to work with a different one. Since the original developer was unavailable, I disassembled the application, updated the configuration, and then reassembled it.
- mystified5016 2y ago.net is the very obvious exception to this kind of thing, yes. .net very deliberately makes this kind of tampering quite trivial in comparison