PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, November 10, 2022

[FIXED] why does memory address change in Ubuntu and not in Redhat

 November 10, 2022     gdb, linux, redhat, ubuntu     No comments   

Issue

I have this program:

double t;
main() {
}

On Ubuntu, I run:

% gdb a.out
(gdb) p &t
$1 = (double *) 0x4010 <t>
(gdb) run
Starting program: /home/phan/a.out 
[Inferior 1 (process 95930) exited normally]
(gdb) p &t
$2 = (double *) 0x555555558010 <t>

Why did the address change from 0x4010 to 0x555555558010. Is there someway to prevent this? On Redhat, it doesn't do that:

% gdb a.out
(gdb) p &t
$1 = (double *) 0x601038 <t>
(gdb) r
Starting program: /home/phan/a.out 
[Inferior 1 (process 23337) exited normally]
(gdb) p &t
$2 = (double *) 0x601038 <t>

BTW, this only occurs in Ubuntu 18.04. In Ubuntu 16.04, it works exactly as Redhat, for example the address is the same before and after.


Solution

You are presumably seeing pre and post-relocation addresses for the .bss segment.

You can avoid this by disabling position independent executables, thus making gcc choose the final address of the .bss register up front:

gcc -no-pie foo.c

-static would have the effect.

I don't know why there'd be a difference between Ubuntu and Redhat though.



Answered By - that other guy
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing