LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-25-2018, 06:24 AM   #1
csakthikumar
LQ Newbie
 
Registered: May 2017
Posts: 10

Rep: Reputation: Disabled
Different assembly code generated when no change in code or compiler options


Hi,
I am facing a weird issue, I used MIPS cross compiler to build MIPS based libs and lib building was fine. The very next day I build MIPS based libs again without changing code/compiler/compiler options(No change in compilation environment or code) but the newly generated libs are different from the previous one. To debug the issue further I took objdump of old and new libs I can see only 1 difference and that is as below

Objdump snippet from Old Lib:
Code:
    a8e0:	8fc20124 	lw	v0,292(s8)
    a8e4:	8fc3012c 	lw	v1,300(s8)
    a8e8:	8c420000 	lw	v0,0(v0)
    a8ec:	afc20110 	sw	v0,272(s8)
    a8f0:	8c630018 	lw	v1,24(v1)
    a8f4:	8fc2012c 	lw	v0,300(s8)
    a8f8:	afc30114 	sw	v1,276(s8)
    a8fc:	8fc30110 	lw	v1,272(s8)
Objdump snippet from New Lib:
Code:
    a8e0:	8fc20124 	lw	v0,292(s8)
    a8e4:	8fc3012c 	lw	v1,300(s8)
    a8e8:	8c420000 	lw	v0,0(v0)
    a8ec:	afc20110 	sw	v0,272(s8)
    a8f0:	0060102d 	move	v0,v1
    a8f4:	8c630018 	lw	v1,24(v1)
    a8f8:	afc30114 	sw	v1,276(s8)
    a8fc:	8fc30110 	lw	v1,272(s8)
Can you please help me understand what is the root cause for the same.
 
Old 06-25-2018, 07:49 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
Well, is it stated in the documentation that the compiler is deterministic, i.e. it always generates the same output from the same input?
 
Old 06-25-2018, 11:36 AM   #3
csakthikumar
LQ Newbie
 
Registered: May 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
Well, is it stated in the documentation that the compiler is deterministic, i.e. it always generates the same output from the same input?
No but was just wondering what can cause a compiler to spit different outputs even though source code and build environment is same
 
Old 06-26-2018, 12:12 PM   #4
dogpatch
Member
 
Registered: Nov 2005
Location: Central America
Distribution: Mepis, Android
Posts: 490
Blog Entries: 4

Rep: Reputation: 238Reputation: 238Reputation: 238
Quote:
Originally Posted by NevemTeve View Post
Well, is it stated in the documentation that the compiler is deterministic, i.e. it always generates the same output from the same input?
So... unless the compiler specifically states that it is deterministic, the OP should just shrug his shoulders and accept it? IMHO, caprice should be expected in government policies, not in compilers. Am subscribing to this mostly because i find it intriguing and would like to be notified if csakthikumar ever finds the reason behind this.
 
Old 06-26-2018, 02:46 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
My experience is:

Same code (no changes)
Same tools (no changes)
Same process/makefile (no changes)

Result EXACTLY the same.

I'd say for years, since the 70's, we either assemble, or compile. And once we had a release, we froze that code, along with the tools to build it and many, many times we verified that it generated exactly the same result. This used to be part of a submission process for one of my former employer's freeze process. We had to prove that we could regenerate the exact same result. If not, we did something wrong.

Any chance that you have a rolling distribution where something got upgraded?
 
Old 06-26-2018, 08:28 PM   #6
csakthikumar
LQ Newbie
 
Registered: May 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by dogpatch View Post
So... unless the compiler specifically states that it is deterministic, the OP should just shrug his shoulders and accept it? IMHO, caprice should be expected in government policies, not in compilers. Am subscribing to this mostly because i find it intriguing and would like to be notified if csakthikumar ever finds the reason behind this.
Exactly this is the first time I am seeing like this. I preassumed compiler will always give the same output if the environment and code is not modified
 
Old 06-26-2018, 08:32 PM   #7
csakthikumar
LQ Newbie
 
Registered: May 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
My experience is:

Same code (no changes)
Same tools (no changes)
Same process/makefile (no changes)

Result EXACTLY the same.

I'd say for years, since the 70's, we either assemble, or compile. And once we had a release, we froze that code, along with the tools to build it and many, many times we verified that it generated exactly the same result. This used to be part of a submission process for one of my former employer's freeze process. We had to prove that we could regenerate the exact same result. If not, we did something wrong.

Any chance that you have a rolling distribution where something got upgraded?
I have also got this issue during code freeze process aka source code consistency process only. Also I am able to reproduce this issue. When I build the libs like 26 times I am able to find that the libs being built 25 times is different from the 26th time. Even though this 25 - 26 number is not consistent.
 
Old 06-27-2018, 06:48 AM   #8
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,883
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
I know I wrote a few paragraphs, but I actually had a question at the end of that.
Quote:
Originally Posted by rtmistler View Post
Any chance that you have a rolling distribution where something got upgraded?
Does sound like you answered though when you mention you can build repeatedly OK and then see a fault one time.

Last edited by rtmistler; 06-27-2018 at 06:49 AM.
 
Old 06-28-2018, 05:01 AM   #9
csakthikumar
LQ Newbie
 
Registered: May 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rtmistler View Post
I know I wrote a few paragraphs, but I actually had a question at the end of that.Does sound like you answered though when you mention you can build repeatedly OK and then see a fault one time.
in my OP have mentioned that there is no changes in compiler or related tools or literally anything else in the build environment. On further analysis have found that when we have multiple local variable declaration that is where this sort of problem is happening Once I finish my deep analysis I will post a report over the same.
 
Old 06-28-2018, 06:07 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,927

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
Theoretically there are a few tools available to detect [almost] any kind of changes, so you can compare two executions of the build process. But I'm not really sure you can do that in your case.
The changes could be: different source code, different tools, different environment, different os/platform/user/hardware, but unfortunately it can be simply the date which will be different every time.
Yes, in general from the same source the system should generate the same result, but without knowing the details hard to check what can influence your build process and what kind of differences have any effect on the result.
 
Old 06-28-2018, 06:18 AM   #11
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,869
Blog Entries: 1

Rep: Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870Reputation: 1870
Is the test automatized? I mean something like this:
Code:
for i in $(seq 100); do
    gcc-toplatform ... -o suspected.o -c suspected.c
    printf "%s %s\n" "$(date +%Y%md%d.%H%M%S)" "$(md5sum suspected.o)" >>checksum.log
done
 
Old 06-28-2018, 06:20 AM   #12
csakthikumar
LQ Newbie
 
Registered: May 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
Theoretically there are a few tools available to detect [almost] any kind of changes, so you can compare two executions of the build process. But I'm not really sure you can do that in your case.
The changes could be: different source code, different tools, different environment, different os/platform/user/hardware, but unfortunately it can be simply the date which will be different every time.
Yes, in general from the same source the system should generate the same result, but without knowing the details hard to check what can influence your build process and what kind of differences have any effect on the result.
different source code, ---> my builds will have the sha id based on which the build has happened. This matches
different tools, ---> this is a CI environment which has not been modified or patched for the past 6 months atleast
different environment, ---> as above
different os/platform/user/hardware ---> as above

Adding to that our deliverable will be in terms of libs and for each platform we used to build 12 libs of which only 1 lib is mismatching on displaying the assembly similar to the one present in OP. It has been confirmed that only two instructions are swapped.
 
Old 06-28-2018, 06:27 AM   #13
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,927

Rep: Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320Reputation: 7320
can you reproduce it anyway? how? or it just happened once....
 
Old 06-28-2018, 06:38 AM   #14
csakthikumar
LQ Newbie
 
Registered: May 2017
Posts: 10

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by NevemTeve View Post
Is the test automatized? I mean something like this:
Code:
for i in $(seq 100); do
    gcc-toplatform ... -o suspected.o -c suspected.c
    printf "%s %s\n" "$(date +%Y%md%d.%H%M%S)" "$(md5sum suspected.o)" >>checksum.log
done
yes something like this since mine is lib i can just do "fc" over it with the base lib and break execution when both lib mismatches

Quote:
Originally Posted by pan64 View Post
can you reproduce it anyway? how? or it just happened once....
No I can reproduce it and I kindoff figured it out what the problem is too. NO trying to use asm to remove this kindoff issue
 
  


Reply

Tags
assembly-language, gcc



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Assembly code rocks! dogpatch Programming 15 04-13-2018 09:32 PM
[SOLVED] assembly code ridoy Programming 3 03-29-2011 02:12 PM
How to convert Assembly code to "C" source code ssg14j Programming 2 08-01-2005 12:48 PM
doubts about assembly code generated from gcc morph_ind Programming 9 05-28-2005 12:08 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration