Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 356519 - ELF header reader makeShort() bug
Summary: ELF header reader makeShort() bug
Status: RESOLVED FIXED
Alias: None
Product: CDT
Classification: Tools
Component: cdt-core (show other bugs)
Version: 8.0   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: 8.1.0   Edit
Assignee: John Cortell CLA
QA Contact: Doug Schaefer CLA
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-01 15:57 EDT by John Dallaway CLA
Modified: 2012-05-14 00:34 EDT (History)
2 users (show)

See Also:


Attachments
Fix for makeShort() plus RX and RL78 machine IDs (1.66 KB, patch)
2011-09-01 16:06 EDT, John Dallaway CLA
no flags Details | Diff
Updated patch (3.66 KB, patch)
2012-02-24 14:20 EST, John Cortell CLA
john.cortell: iplog-
Details | Diff
Updated patch (19.63 KB, patch)
2012-02-24 14:27 EST, John Cortell CLA
john.cortell: iplog-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
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