2

When reading https://en.wikipedia.org/wiki/Address_space_layout_randomization, I encountered a term:

Position-independent executable (PIE) implements a random base address for the main executable binary and has been in place since 2003. It provides the same address randomness to the main executable as being used for the shared libraries.

What does main executable binary mean here? Is it just a tu/source file that contains the main function?

Chen Li
  • 4,824
  • 3
  • 28
  • 55
  • 1
    The source file is written to be human understandable. The executable is compiled to be machine understandable. The executable doesn't have a main function, rather an initial address to begin executing processor commands. – Fiddling Bits Jan 16 '20 at 14:08
  • Not clear that this question is on-topic. In context however it is clear I think that it refers to the executable file you launch as distinct from any _shared libraries_ that it may cause to be dynamically linked. For example it refers to _"library base and main executable"_ elsewhere. – Clifford Jan 16 '20 at 14:09

2 Answers2

2

It means the output of the linker when you build your executable, the so-called a.out file in the *nix world. The compiler creates object files and the linker resolves all the dependencies into an a.out file. Some of those dependencies will be external (dynamic link libraries).

The main executable will be the file that the os (possibly the linker) loads initially when you execute it. Subsequent loads would be the dynamic link libraries that are external dependencies created during the build process.

Jeff Holt
  • 2,940
  • 3
  • 22
  • 29
  • 3
    You were doing well until you mentioned a `main()` function. That is language specific and is an unnecessary and potentially confusing addition since the word "main" in "main executable" has nothing to do with the arbitrary source level symbol name of the binary executable entry point. The question is about loading an executable, not linking it. – Clifford Jan 16 '20 at 14:16
  • It is perhaps implicit in the platforms that are discussed in the article, `ld` being the primary link tool that generates PIEs, but the meaning of "main executable" as a concept does not depend on that. That has meaning on any platform with dynamic linking. I was being a little pedantic perhaps, but I did not want the OP to persist in the conflation of `main()` and "main executable" - the terms are not related so best not mentioned. Moreover I am pretty sure even with `ld` you can specify an alternative entry point symbol by command switch. – Clifford Jan 16 '20 at 14:28
  • Actually I take that back - the article discusses PIE on Windows - where `ld` is a less commonly used linker. – Clifford Jan 16 '20 at 14:31
  • I just looked at GNU's `ld` and don't see any entry point variability (but I do see allowance for changing argv[0]). But even so, you're right to mention the variability in language. And I'm glad you mentioned it. – Jeff Holt Jan 16 '20 at 14:31
  • @Clifford To the entry point variability thing, I now see you were probably referring to the creation of the executable. My comment back was regarding the loading of the executable prior to it calling the entry point. Of course, you're correct that you can specify an alternative entry point when ld creates the executable. I'll wager most other linkers can do it too. – Jeff Holt Jan 16 '20 at 15:53
-2

I assume it is the binary with main() function, so the program in strict sense.

Previously, programs were loaded on specific addresses, but dynamic libraries were already loaded at different addresses, so I think the main here it is just to empathize that it is for the program binary and not for the library binaries.

Giacomo Catenazzi
  • 8,519
  • 2
  • 24
  • 32
  • a `main()` function is specific to a programming language. A machine executable does not have one, and the language used to generate it may not have one either. The meaning is clear in the context of the whole article, and the question probably off-topic in any case. – Clifford Jan 16 '20 at 14:12
  • @Clifford: we are discussing of Linux. `main()` has a well defined role in POSIX (-like) world. i think you are going on the very pedantic side (entry point instead of main). – Giacomo Catenazzi Jan 16 '20 at 14:17
  • Linux is not mentioned in the question and the article discusses PIEs on Windows in any case. Pedantic perhaps, but the symbol `main` is not related to the word "main" in the term "main executable" - that is just coincidental, so best not mentioned in case it is assumed it is a "main executable" _because_ it has an entry point that in the source happens to be called `main`. – Clifford Jan 16 '20 at 14:35