Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 356519

Summary: ELF header reader makeShort() bug
Product: [Tools] CDT Reporter: John Dallaway <john>
Component: cdt-coreAssignee: John Cortell <john.cortell>
Status: RESOLVED FIXED QA Contact: Doug Schaefer <cdtdoug>
Severity: normal    
Priority: P3 CC: john.cortell, malaperle
Version: 8.0   
Target Milestone: 8.1.0   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
Fix for makeShort() plus RX and RL78 machine IDs
none
Updated patch
john.cortell: iplog-
Updated patch john.cortell: iplog-

Description John Dallaway CLA 2011-09-01 15:57:18 EDT
Build Identifier: cdt_8_0 and HEAD

org.eclipse.cdt.utils.elf.Elf.ELFhdr.makeShort() returns an incorrect value when the less significant input byte is greater than 0x7f. This prevents correct calculation of the CPU name string when the ELF machine ID is in the range 0x80-0xff.

The implementations of makeInt() and makeLong() may also be buggy.

Issue discovered when adding EM_RX and EM_RL78 machine IDs.

Reproducible: Always

Steps to Reproduce:
1. Build an ELF object file with an ELF machine ID which is known to CDT and in the range 0x80-0xff.

2. Observe that the CPU name is calculated to be "none".
Comment 1 John Dallaway CLA 2011-09-01 16:06:22 EDT
Created attachment 202637 [details]
Fix for makeShort() plus RX and RL78 machine IDs

The patch avoids treating individual input bytes as negative numbers. It should apply to the cdt_8_0 branch and HEAD.
Comment 2 John Cortell CLA 2012-02-24 14:20:12 EST
Created attachment 211599 [details]
Updated patch

Did some refactoring and added tests. Also optimized contributed solution (avoid unnecessary &0xff operations).
Comment 3 John Cortell CLA 2012-02-24 14:21:19 EST
Pushed to master (CDT 8.1)
Comment 4 John Cortell CLA 2012-02-24 14:27:59 EST
Created attachment 211602 [details]
Updated patch

Previous patch lacked new files
Comment 5 John Dallaway CLA 2012-02-24 15:19:58 EST
(In reply to comment #3)
> Pushed to master (CDT 8.1)

Thank you, John.
Comment 6 John Cortell CLA 2012-02-24 15:22:45 EST
(In reply to comment #5)
> Thank you, John.

Sure thing. Please validate the patch in your environment, if you can.
Comment 7 CDT Genie CLA 2012-02-29 13:25:56 EST
*** cdt git genie on behalf of John Cortell ***

    Bug 356519 - ELF header reader makeShort() bug

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=b4da3bb8f027a1c99a7e99e14d0136becf291c81
*** cdt git genie on behalf of John Cortell ***

    Bug 356519 - ELF header reader makeShort() bug

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=b4da3bb8f027a1c99a7e99e14d0136becf291c81
Comment 8 CDT Genie CLA 2012-02-29 13:25:56 EST
*** cdt git genie on behalf of John Cortell ***

    Bug 356519 - ELF header reader makeShort() bug

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=b4da3bb8f027a1c99a7e99e14d0136becf291c81
*** cdt git genie on behalf of John Cortell ***

    Bug 356519 - ELF header reader makeShort() bug

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=b4da3bb8f027a1c99a7e99e14d0136becf291c81
Comment 9 CDT Genie CLA 2012-02-29 13:25:59 EST
*** cdt git genie on behalf of John Cortell ***

    Bug 356519 - ELF header reader makeShort() bug

[*] http://git.eclipse.org/c/cdt/org.eclipse.cdt.git/commit/?id=45c5f16e074987ea3e883f148927f24a51ae8716