public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* code that went to process segment now goes to shared segment
@ 2019-12-06 13:03 bmuller@inf.ufpr.br
  2019-12-06 13:18 ` Alexander Monakov
  0 siblings, 1 reply; 2+ messages in thread
From: bmuller@inf.ufpr.br @ 2019-12-06 13:03 UTC (permalink / raw)
  To: gcc-help

I wrote a program that uses some dynamic libraries I designed. Then, I
compiled and executed a program that prints the address of a lot of things
global variables, shared procedures and the procedure main():

long int main ()
{
 ...
  printf ("Procedure main: (Address=%p)\n", main);
...
}

After compiling with gcc 5.4.0 (gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0
20160609),  the execution shows that the procedure "main" was at address
0x400776, that is, in the process segment (along the global variables).

After compiling with gcc 7.4.0 (gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0),
the execution  shows that the procedure "main" went to address
0x55bbddb7e7fa, that is inside the dynamic segment área (along the global
variables).

I guess that this "functional" change occurred along the GCC 6.0 changes,
but I could not find the motivation for it in the wiki, faq or the 6.0
change docs.

My question is if there is some documentation that presents the motivation
for this changes: advantages, disadvantages and if some abnormal behavior
was reported.

I teach operating systems, and some students reported that the programs I
used for exams were not producing the former addresses generating unusual
results. I'll have to rewrite my code, but I'd like to know if I should be
prepared for something... strange.

Thanks,

Bruno

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: code that went to process segment now goes to shared segment
  2019-12-06 13:03 code that went to process segment now goes to shared segment bmuller@inf.ufpr.br
@ 2019-12-06 13:18 ` Alexander Monakov
  0 siblings, 0 replies; 2+ messages in thread
From: Alexander Monakov @ 2019-12-06 13:18 UTC (permalink / raw)
  To: bmuller@inf.ufpr.br; +Cc: gcc-help

[-- Attachment #1: Type: text/plain, Size: 1349 bytes --]

On Fri, 6 Dec 2019, bmuller@inf.ufpr.br wrote:

> After compiling with gcc 5.4.0 (gcc (Ubuntu 5.4.0-6ubuntu1~16.04.12) 5.4.0
> 20160609),  the execution shows that the procedure "main" was at address
> 0x400776, that is, in the process segment (along the global variables).
> 
> After compiling with gcc 7.4.0 (gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0),
> the execution  shows that the procedure "main" went to address
> 0x55bbddb7e7fa, that is inside the dynamic segment área (along the global
> variables).
> 
> I guess that this "functional" change occurred along the GCC 6.0 changes,
> but I could not find the motivation for it in the wiki, faq or the 6.0
> change docs.
> 
> My question is if there is some documentation that presents the motivation
> for this changes: advantages, disadvantages and if some abnormal behavior
> was reported.

You're seeing that newer Ubuntu configures GCC to produce position-independent
executables by default (look for --enable-default-pie in output of 'gcc -v').

Each distribution decides for itself whether to enable PIE by default or not,
the motivation is security hardening; I think you can look for articles on
ASLR, address space layout randomization, for further info.

Upstream GCC did not change its defaults with regard to PIE-by-default, this
was and remains up to distributions.

Alexander

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-06 13:18 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-06 13:03 code that went to process segment now goes to shared segment bmuller@inf.ufpr.br
2019-12-06 13:18 ` Alexander Monakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).