vegard,
@vegard@mastodon.social avatar

Are these all the special sections that run code on program init/exit? Did I miss any?

.section .preinit_array; .quad fun
.section .init, "ax"; callq fun
.section .init_array; .quad fun
.section .ctors, "aw"; .quad fun
.section .dtors, "aw"; .quad fun
.section .fini_array; .quad fun
.section .fini, "ax"; callq fun

amonakov,
@amonakov@mastodon.gamedev.place avatar

@vegard you absolutely did, because you're not asking the right question. The right question is, what makes code from those sections run at startup?

pervognsen,
@pervognsen@mastodon.social avatar

@amonakov @vegard Hint: ld --verbose :)

vegard,
@vegard@mastodon.social avatar

@amonakov 🤔 well, obviously there's _start/main and ld.so itself but I meant more like "things I can link with an existing program/library and have it run without modifying anything else".

@pervognsen So .ctors.* and .dtors.* work, anything else..?

pervognsen,
@pervognsen@mastodon.social avatar

@vegard @amonakov Sorry, had to go chase through the code myself. It actually didn't work how I thought I remembered it did. The entry point is _start, which is defined in your libc. I looked at glibc and you can see its target-agnostic code for calling init/fini here: https://github.com/lattera/glibc/blob/master/csu/elf-init.c#L60. I thought maybe some of the other sections just got concatenated into these by the linker script but that doesn't look like what's happening.

pervognsen,
@pervognsen@mastodon.social avatar

@vegard @amonakov My recollection (apparently hallucinated) was a lot of the init sequencing was conducted just by the section concatenation order in the linker script but it looks like almost everything is done by libc calling into the sections delimited by the provided *_start and *_end symbols. Which I guess does make more sense now that I think about it since it puts the libc startup code more in the driver's seat.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • rosin
  • osvaldo12
  • thenastyranch
  • DreamBathrooms
  • everett
  • magazineikmin
  • InstantRegret
  • Youngstown
  • slotface
  • mdbf
  • love
  • kavyap
  • GTA5RPClips
  • khanakhh
  • normalnudes
  • modclub
  • ethstaker
  • Leos
  • ngwrru68w68
  • Durango
  • tacticalgear
  • cubers
  • anitta
  • provamag3
  • tester
  • cisconetworking
  • megavids
  • JUstTest
  • All magazines