digitalmars.D.learn - [DTrace probe] is there a [portable] way to add section to elf
I'd like to add (and modify) section to ELF executable to implement DTrace probes. DTrace does it in probe assembly: ``` __asm__ __volatile__ ( "990: nop .pushsection .note.stapsdt,\"?\",\"note\" .balign 4 .4byte 992f-991f, 994f-993f, 3 991: .asciz \"stapsdt\" 992: .balign 4 993: .8byte 990b .8byte _.stapsdt.base .8byte 0 .asciz \"myapp\" .asciz \"func_call\" .asciz \"%n[_SDT_S1] %[_SDT_A1] %n[_SDT_S2] %[_SDT_A2]\" 994: .balign 4 .popsection" :: [_SDT_S1] "n" (SNIPPED_ONE), [_SDT_A1] "nor" ((a)), [_SDT_S2] "n" (SNIPPED_TWO), [_SDT_A2] "nor" ((b)) ); ``` So I need a way to add no op operation and define some data in `.note.stapsdt` section. This page https://dlang.org/spec/iasm.html does not contain any information about sections
Oct 23 2019
On Wednesday, 23 October 2019 at 15:24:13 UTC, drug wrote:I'd like to add (and modify) section to ELF executable to implement DTrace probes. DTrace does it in probe assembly: ``` __asm__ __volatile__ ( "990: nop .pushsection .note.stapsdt,\"?\",\"note\" .balign 4 .4byte 992f-991f, 994f-993f, 3 991: .asciz \"stapsdt\" 992: .balign 4 993: .8byte 990b .8byte _.stapsdt.base .8byte 0 .asciz \"myapp\" .asciz \"func_call\" .asciz \"%n[_SDT_S1] %[_SDT_A1] %n[_SDT_S2] %[_SDT_A2]\" 994: .balign 4 .popsection" :: [_SDT_S1] "n" (SNIPPED_ONE), [_SDT_A1] "nor" ((a)), [_SDT_S2] "n" (SNIPPED_TWO), [_SDT_A2] "nor" ((b)) ); ``` So I need a way to add no op operation and define some data in `.note.stapsdt` section. This page https://dlang.org/spec/iasm.html does not contain any information about sectionsI hope you are not mixing up D SCRIPTING language that is used by Dtrace and D PROGRAMMING language. Second thing is that ELF format is used by Linux and other operating systems use different executable formats (mach-0 for macOs and PE for windows). So by definition its not portable. D's inline asm does not provide a way to modify *.obj files. It just insert your asm at that place.
Oct 24 2019